Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Hide Svelte component from outside script

I am importing a third-party Svelte3 component with several children. For the sake of example, the third-party component looks like the following:

<script>
  import Child1 from './third-party/Child1.svelte';
  import Child2 from './third-party/Child2.svelte';
</script>

<div>
  <Child1/>
  <Child2/>
</div>

What would be the cleanest way to hide one of the children components from within my app (or from the dev console) given that:

  1. it has no easily identifiable CSS selector, and
  2. I cannot modify the third-party code?

In Vue, I would use the root instance, but is this possible in Svelte?

Thank you very much!

Guido

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There is no clean way. Messing with the DOM from outside a component is a hacky solution and can lead to unpredictable results.

This is a feature the third party needs to add to their public api.

An option for the third party is to expose the feature is via props using $set using the component api:

// App.svelte
<script>
import Child1 from './third-party/Child1.svelte';
import Child2 from './third-party/Child2.svelte';

export let child2Visible = true;
</script>

<div>
    <Child1/>
    {#if child2Visible}
      <Child2/>
    {/if}
</div>
// my-app.js
import App from "./App.svelte";

window.app = new App({target});
// From dev console
app.$set({ child2Visible: false })

Another way for the third party is to expose a way for setting a store value which could toggle some of the ui.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!