-
Notifications
You must be signed in to change notification settings - Fork 49
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
Svelte 5: Reactivity is not triggered when changing data #500
Comments
@vyconm which version of @unovis/svelte are you using? |
latest stable, that being 1.4.5 |
We have a beta version which hopefully will fix this issue, see here: #487 (comment). Do you mind give it a try? |
I tried the 1.5.0-svelte0 of /ts and /svelte, unfortunately didnt change the issue. As far as I understand, this won't be resolved until the components themselves use svelte 5 syntax, which unfortunately would be breaking for svelte <= 4 users. The Workaround for now is to wrap the component in a {#key} block with the data - not elegant, but works great. I will try to manually rewrite the components in svelte 5 and see if that resolves it, to test my theory. |
I may very well be too stupid to write node-modules, somehow I get the same error even when forcing runes mode, which seems nonsensical. I quickly ported the single-container.svelte to this:
The error for some reason stays the same, even when running dev --force. I might be out of my comfort zone here, hope I can still provide some insight. |
@vyconm Do you think you can provide a StackBlitz example showing the issue you've mentioned? @pingu-codes maybe you can provide some insights on this? |
I'll try tomorrow! |
I don't have much experience with Svelte, but I just made 2 examples, Svelte 4 and Svelte 5. Doesn't seem like the data is updating in V5. @pingu-codes any thoughts? |
Svelte 5 changed how reactivity works, using Signals (called runes) like in SolidJs. Nevertheless, svelte promises full backwards compatability so even your svelte 5 example with old syntax is supposed to work. Weirdly it still wants updated Syntax for unovis, which is confusing. |
I made a couple of changes which seem to work for the line component: // variable to store the previous data
let prevData: Datum[] = undefined;
onMount(() => {
// ...
// data must be set for the initial render to work
component.setData(data);
// ...
});
// this is disabled
// $: component?.setData(data);
let animationFrame = 0;
const triggerReRender = () => {
component?.setData(data);
if (typeof requestAnimationFrame === 'undefined') {
component?._render();
return;
}
if (animationFrame) {
cancelAnimationFrame(animationFrame);
}
animationFrame = requestAnimationFrame(() => {
component?._render();
animationFrame = 0;
});
};
// if the data has been changed the component will have the data set AND be re-rendered with ._render()
$: if (prevData !== data || (data !== undefined && prevData === undefined)) {
prevData = data;
triggerReRender();
} |
@pingu-codes did you get a chance to look at the Svelte 5 example I made? If Svelte 5 is backwards compatible, why isn't the updating button working? |
Hey @lee00678, I just took a look. The update button is working and the array is being updated if you console.log it. The chart isn't being updated due to the problems with svelte 5 and unovis reactivity when data changes 😔 |
I am not sure, if there is any workaround to this other than fully migrating unovis/svelte to svelte 5. Creating a Seperate Component to wrap unovis in, which runs in legacy mode, does not help the issue.
As the code is auto-generated according to the code comments, would that be fairly straight forward?
The text was updated successfully, but these errors were encountered: