Closed SAG-Storck closed 1 month ago
The update introduces a new boolean variable mounted
in the Particles.svelte
component. This variable enhances the component's lifecycle management by ensuring that certain actions within the loadParticles
function only execute if the component is still mounted, preventing potential errors related to asynchronous operations after the component has been unmounted.
File Path | Change Summary |
---|---|
components/.../Particles.svelte |
Added mounted variable and updated loadParticles logic. |
🐰✨ In the realm of code, where particles dance,
A wise rabbit adds a check with a glance.
"Are we still mounted?" it asks with care,
Ensuring stability is present, not just flair.
Hop and code, let errors be banned! 🎉
🐰✨
components/svelte/src/lib/Particles.svelte (3)
`12-12`: The introduction of the `mounted` variable is correctly implemented for tracking the component's mount state. --- `49-49`: Setting `mounted` to `true` in `onMount` and the non-blocking call to `loadParticles` are correctly implemented to align with component lifecycle events. --- `56-56`: The addition of the `mounted` check in `loadParticles` is crucial for ensuring that the component is fully ready before loading particles, thus addressing the issue of premature loading.
Hey, thanks for your work, can this be merged into the main? Due to this bug Particles is unusable in Sveltekit apps
When navigating back to a page that includes the Particles component in SvelteKit (at least in Svelte 5), the load function of the engine is sometimes ran before the Particles component is fully mounted.
When this happens, the DOM element ist not present yet and as a fallback, the engine will create a new element directly below the body. This will cause a duplicate particles div to exist.
By checking if the component is mounted before loading the particles, this should be prevented.
Summary by CodeRabbit