-
Notifications
You must be signed in to change notification settings - Fork 33
fix: $destroy and createRoot are no more #328
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ping me once this is in and I'll rebase #325 accordingly
Feel free to ping me once this is in and I'll rebase #325 accordingly
I will! I'm still figuring out how to deal with $set. I'll push the code I have right now for shared lulz. It's not yet working, though.
I added the mount / unmount changes to #325 before you made this PR, which will at least unblock the majority of testing. I'm starting to think that either:
rerenderwon't be supported in Svelte 5- Instead, the complexity is pushed to the user, who will need to do something like
// comp.test.svelte.js const props = $state({ name: 'hello' }) render(Comp, { props }) // ... act(() => (props.name = 'goodbye'))
- This is how
solid-testing-libraryoperates
- Instead, the complexity is pushed to the user, who will need to do something like
- We'll need to introduce a build step into this library so we can use
$stateourselves- I actually don't know if this will work
Either path feels like a bit of a bummer!
* `rerender` won't be supported in Svelte 5 * Instead, the complexity is pushed to the user, who will need to do something like ```js // comp.test.svelte.js const props = $state({ name: 'hello' }) render(Comp, { props }) // ... act(() => (props.name = 'goodbye')) ``` * This is how `solid-testing-library` operates
Yup, that's what I think as well. I'm trying to change the rerender test to use that ^^^ pattern, but for some reason it doesn't react to props.name = 'goodbye'. But I used a waitFor, not an act, so I'll try that.
* We'll need to introduce a build step into this library so we can use `$state` ourselves
I think we just need to change the name of the test file to be test.svelte.js for the compiler to do the right thing. I'll say this with more conviction once the test is passing. :-)
Right now my battle plan is
- find out the Way That Works with Svelte 5.
- see how that can fit with the previous versions of svelte. Worst case we might have to split things and have
import {} from '@testing-library/sveltefor the latest supported version andimport {} from '@testing-library/svelte/svelteXforXthat are legacy versions and upcoming versions. - Depending on (2), organize the tests to cover the maximum without going insane.
So yeah, weeeeee, supporting several major versions is fun, fun, fun. 🤪
* I actually don't know if this will workEither path feels like a bit of a bummer!
202aefe to
06ba816
Compare
For now I've resorted to use the legacy API, as the use of runes don't seem to work in the test environment (which, mind you, could be a problem on this side of the keyboard) and the important part is to have the package work with Svelte 5.
06ba816 to
44b20b4
Compare
46c2e22 to
2b1449b
Compare
2b1449b to
6f494ad
Compare
@mcous This is not the patch we deserve, but probably the patch we need. I'm using the svelte/legacy API of svelte 5 as I could not make the runes work in the testing context yet. I've also skipped 2 tests for svelte 5 and happy-dom because they are failing in a weird way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes because this breaks type exports in package.json for the existing library.
Additionally, the separate entry points for v4 vs v5 seems a little unnecessary from a technical standpoint, because the public APIs remain unchanged. What's the value of it this approach over what's currently in #325, where pure.js continues to support both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, we need to make sure we don't drop this types export, or it'll break TS using more modern moduleResolution modes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the types key right below the exports take care of that, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, no. If TS sees "exports" in moduleResolute: nodenext or bundler and there's no exports[].types it'll get sad
See #228
package.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a corresponding types esport for Svelte 5?
src/__tests__/context.test.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In another test I used the user-agent to test for jsdom vs happy-dom. It's ever-so-slightly janky, but I like it because it doesn't require adding more environment variables / setup. Using an environment variable makes it harder to use vitest directly, which I do with some frequency to noodle on stuff
Related, should we have a little __tests__/environment.ts helper file that exports IS_SVELTE_5, IS_HAPPY_DOM, IS_JSDOM, etc. to make these a little less repetitive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have a little tests/environment.ts helper file that exports IS_SVELTE_5, IS_HAPPY_DOM, IS_JSDOM, etc. to make these a little less repetitive?
Yeah, that would make a lot of sense.
src/pure.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I'm open to the separate entry points approach! That being said, I don't see anything in this PR that really justifies it. Is it a future-proofing thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the previous comment, it's to deal with import from 'svelte/legacy'. We could probably dig out darker magic to do it another way, but I do feel there will be other things in Svelte 5 that will be easier if we just have different files implementing the same(ish) interface rather than having a file that tries to satisfy all versions at once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh, yeah duh, my bad, that makes total sense.
Aside: this makes me think dropping 3.0 in the next branch (in a separate PR to be responsible about it) will make things easier.
I'm not totally sure what to do about collecting multiple breaking changes without a prerelease version. Maybe we should switch over to an beta branch for breaking changes? Or consider switching next to be a prerelease in semantic-release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: this makes me think dropping 3.0 in the next branch (in a separate PR to be responsible about it) will make things easier.
What would we cut off?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a lot of duplication for little payoff. If you want to have separate entry points, would it be better to re-export pure.js's exports and only override the public methods that changed?
Alternatively, can we move the split to an internal facade instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My development steps are
- Make it
- Make it work
- Make it pretty
This PR is at stage (2). all the functions that aren't different in svelte5.js should really be imported from pure.js. But first I was interested to see how deep the hole had to be. And then backfill and tidy up the garden again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, happy to defer to whatever approach you want to take. Just wanted to point out opportunities nip stuff in the bud LoC-wise
What's the value of it this approach over what's currently in #325, where
pure.jscontinues to support both?
import {...} from 'svelte/legacy' goes boom for Svelte 3 that didn't have that package.
No description provided.