-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
charts-svelte: cannot read property 'removeChild' of null when using <svelte:component /> #799
Comments
@metonym could you please chime in here? |
@danielboven Thank you for raising the issue and the detailed reproduction steps. I was able to reproduce the error on my local machine with Rollup and the latest You're absolutely right when you mention #5038, where the However, I think the underlying issue is that the $: if (element && Chart) {
chart = new Chart(element, { data, options });
dispatch("load", chart);
} I'll need to dig deeper into this, but |
Following up on this after drafting a PR (#800) @danielboven correctly identifies Instead of invoking the destroy method, the solution is to:
- chart.destroy();
+ chart.components.forEach((component) => component.destroy());
+ chart = null; |
* fix(svelte): rewrite BaseChart to reload chart instance Fixes #799 * refactor(svelte): remove unnecessary afterUpdate method * chore(svelte): keep the PR scoped
…ase-chart * fix(svelte): rewrite BaseChart to reload chart instance Fixes carbon-design-system#799 * refactor(svelte): remove unnecessary afterUpdate method * chore(svelte): keep the PR scoped
I am submitting a...
charts version:
Issue description
With the Svelte version of Carbon charts everything seems to work as expected, except when using the special element
<svelte:component this={componentName}>
. ThecomponentName
variable refers to a reactive variable pointing to, for example, aPieChart
,DonutChart
,BarChartSimple
import. When changing this variable I get an error:Uncaught (in promise) TypeError: Cannot read property 'removeChild' of null
Here is (a simplified version of) my code:
Steps to produce the issue
Using
<svelte:component this={ChartType} />
with a reactive value forChartType
.I have also put the code above in a CodeSandbox, to reproduce this error. I'm getting a very similar error to the one I'm getting in my own project, probably a little different due to the nature and workings of CodeSandbox (compared to working with the Svelte template and Rollup):
Uncaught (in promise) TypeError: Cannot read property 'c' of undefined
Current behavior
When mounting the component and the chart everything works, untill changing the variable used in the
svelte:component
atthis
. In the console an error is thrown and the new chart type doesn't render, other parts of the page (component) also don't respond.Expected behavior
When you change the variable connected to
this
atsvelte:component
, the new chart should render and replace the previous one, just like a component replaces another in the tutorial example.Screenshot or recording
Possible fix to investigate
One of the reasons for this error seems to be relating to third party libraries interfering with Svelte's own DOM manipulation (see sveltejs/svelte#5038 (comment)). Removing the
chart.destroy()
call at the BaseChart.svelte file (line 33) has solved this issue for me. I'm not sure whether this call is necessary for the@carbon/charts
package to function properly, or whether Svelte is able to handle destroying everything related to the component.Without removing this call I have not been able to get the
<svelte:component />
with a changing variable to work, as described in the Svelte tutorial.The text was updated successfully, but these errors were encountered: