SauravKanchan / svelte-chartjs

svelte wrapper for chart.js
https://saurav.tech/mdbsvelte/?path=/story/charts--examples
MIT License
277 stars 34 forks source link

[Bug]: Incompatible with Svelte 5 (pre-release) #158

Open anowell opened 2 months ago

anowell commented 2 months ago

Would you like to work on a fix?

Current and expected behavior

Importing a chartjs component (e.g. Bar) with Svelte 5 (svelte@5.0.0-next.115) yields this error message:

Your application, or one of its dependencies, imported from 'svelte/internal', which was a private module used by Svelte 4 components that no longer exists in Svelte 5. It is not intended to be public API. If you're a library author and you used 'svelte/internal' deliberately, please raise an issue on https://github.com/sveltejs/svelte/issues detailing your use case.

I haven't looked any further than simply confirming the import in this library:

https://github.com/SauravKanchan/svelte-chartjs/blob/4333128d3f47b7e8c9a7a77177ad8592c2e22999/src/utils/svelte.ts#L1-L6

Reproduction

[did not create shareable repro - merely confirmed svelte/internal is import]

chart.js version

4.4.2

svelte-chartjs version

3.1.5

Possible solution

No response

shahedsalehi commented 1 month ago

I just updated my project to svelte svelte@5.0.0-next.123 and I encountered the same issue.

anowell commented 1 month ago

I've implemented a fix here: https://github.com/anowell/svelte-chartjs/commit/155042fc4866615014a12414b3b4815223bcb0b3

It's basically a rewrite of src/util/svelte.ts to work directly with the DOM, and then changes to the base Chart component to setup event listeners more explicitly.

It's certainly a breaking change, and I don't know that it's "correct", but it seems to work, still supports attaching event listeners (tested on the Bar chart storybook story), and I think it cleans them up. And I didn't mean to bump so many devDependencies, but I'm several years removed from the frontend dev tooling ecosystem so might have run a few too many unneeded pnpm commands.

From here, what it would take for this repo/package to support Svelte 5? Is it a new version? Should we wait for Svelte 5 to release? Is there an expectation of Svelte 4 compatibility? Is there some glaring issue with the implementation? Is there some other testing expectation I've completely overlooked? I could put together a PR if the missing pieces are relatively small, or I'm happy to have someone steal whatever they need from my change to put together a better solution.

Fwiw, I'm currently using it in a prototype with no intent to maintain beyond that prototype, so I advise against using my fork for anything beyond experimenting/testing.