Skip to content

fix: ensure SvelteDate cached methods have correct reactive context #14512

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

Closed
wants to merge 4 commits into from

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Dec 2, 2024

Fixes #14506. Because the date prototype methods lazily create deriveds – that also means that it matters what the reactive context is when they're created. If they're created inside another derived then each time the derived runs, the method's deriveds will be destroyed and re-created. This is problematic because if they've already been read in another derived, then they won't be correctly shared.

Instead, we need to ensure we set the reactive context to the nearest parent effect. Deriveds created here are safe because deriveds are only added to parent effects if the derived is read in a non-reactive context.

Copy link

changeset-bot bot commented Dec 2, 2024

🦋 Changeset detected

Latest commit: 78df3d4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Dec 2, 2024

Playground

pnpm add https://pkg.pr.new/svelte@14512

@trueadm trueadm mentioned this pull request Dec 2, 2024
@trueadm trueadm changed the title fix: ensure SvelteDate cached methods have no reactive context fix: ensure SvelteDate cached methods have correct reactive context Dec 3, 2024
@trueadm trueadm marked this pull request as ready for review December 3, 2024 11:34
@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-svelte-14512-svelte.vercel.app/

this is an automated message

@Rich-Harris
Copy link
Member

Is this right? Surely we want to use the reaction that was active when the instance was created, rather than an arbitrary parent effect. Opened #14525 as an alternative

@Rich-Harris
Copy link
Member

(In fact it looks like you reached the same conclusion here? #14506 (comment))

@trueadm trueadm closed this Dec 3, 2024
@trueadm trueadm deleted the date-fix branch December 3, 2024 18:50
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.

SvelteDate no-update
2 participants