Skip to content
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

fix: remove DOM elements even if component creation fails #314

Closed
wants to merge 1 commit into from
Closed

Conversation

mcous
Copy link
Collaborator

@mcous mcous commented Feb 3, 2024

Overview

This PR fixes #190 by simplifying the caching strategy and ensuring the target div is added to the cache as soon as it's created, rather than after the component is rendered.

While working on this PR, I noticed a few inconsistencies with the render function's API, so I filed #312 and #313

Will keep this as a draft until I've smoke tested on my current app's suite

Change log

  • Add target element to cache immediately
  • Consolidate component creation and caching into renderComponent function
  • Consolidate component destruction and target removal into cleanupComponent and cleanupTarget functions
  • Remove component.$$.on_destroy usage I elected to keep this for strict backwards compatibility
    • $$.on_destroy was added in feat: update lib #54, which was a big rewrite about 5 years ago
    • Unfortunately I can't find any historical information about its intent. Perhaps @benmonro remembers?
    • It will not be possible in Svelte 5 as far as I can tell, and I think that's fine, because it's completely unnecessary if the user sticks to unmount and cleanup

@mcous
Copy link
Collaborator Author

mcous commented Feb 7, 2024

Smoke tested by running on my company's ~1000 test suite, everything seemed to behave. Marking this one as ready for review, accordingly!

@mcous mcous marked this pull request as ready for review February 7, 2024 17:53
@@ -18,7 +18,6 @@ exports[`render > should accept svelte component options 1`] = `
<button>
Button
</button>
<!--&lt;Comp&gt;-->
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snapshot removal due to disabling HMR in our test suite

@@ -3,7 +3,7 @@ import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
plugins: [svelte()],
plugins: [svelte({ hot: false })],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disabled HMR because with it enabled, the new test that throws an error in onMount logs a warning message about "full reload required," which doesn't make sense for a test suite.

I think there's something here to add to the documented setup, but vite-plugin-svelte's default setting for hot is more complicated than true/false, so I still need to test to find a good general setting for real projects

@mcous
Copy link
Collaborator Author

mcous commented Feb 13, 2024

The changes in this PR have been merged into next. Gonna close this PR as unnecessary!

@mcous mcous closed this Feb 13, 2024
@mcous mcous deleted the fix-190 branch February 13, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed tests don't remove element from DOM
1 participant