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: correctly notify page store subscribers #13205

Merged
merged 5 commits into from
Jan 6, 2025
Merged

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Dec 20, 2024

fixes #13200

This PR ensures page store subscribers are correctly notified by creating a new object whenever we update the page store. I'm not sure why but when the same page object is used, it doesn't notify subscribers.

There was also another bug where a popstate event would cause subscribers to get notified twice because we were calling root.$set({ page }) in addition to stores.page.notify() when updating the URL.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Dec 20, 2024

🦋 Changeset detected

Latest commit: 6fdf52f

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit 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

@ranjan-purbey
Copy link
Contributor

Thanks for the fix @eltigerchino! Do you think it'd make sense to extract page state to props.page conversion into a utility function to avoid repetitiveness?

@ranjan-purbey
Copy link
Contributor

Probably this line also needs to be updated. @eltigerchino

if (state !== page.state) {
page.state = state;
}

update_url(url);
Copy link
Member Author

@eltigerchino eltigerchino Jan 2, 2025

Choose a reason for hiding this comment

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

update_url already notifies the store so we don't need root.$set({ page }); or it will be notified twice

@ciscoheat
Copy link

Hello, any progress on this one? It's unfortunately causing a bit of problem with Superforms, I've been getting many issues lately about it. It would be great if it can be patched soon. :)

route: page.route,
state: page.state,
status: page.status,
url: page.url
Copy link
Member

Choose a reason for hiding this comment

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

  • is there a reason why we can't just do page: { ...page }?
  • if we can't do that, then this should be moved into a helper function and reused across the change sites to reduce a bit of code size

Copy link
Member Author

@eltigerchino eltigerchino Jan 6, 2025

Choose a reason for hiding this comment

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

Yeah, no clue why but spreading with { ...page } just returns an empty object. Maybe @Rich-Harris knows

Added a helper in 51a5ea7 (#13205)

Copy link
Member

Choose a reason for hiding this comment

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

ah, it's because of the class with $state.raw on it, producing getters which are not spreadable

@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-kit-13205-svelte.vercel.app/

this is an automated message

@dummdidumm dummdidumm merged commit dc8ec1e into main Jan 6, 2025
14 checks passed
@dummdidumm dummdidumm deleted the fix-store-regression branch January 6, 2025 10:33
@github-actions github-actions bot mentioned this pull request Jan 6, 2025
@gyzerok
Copy link

gyzerok commented Jan 7, 2025

@eltigerchino is it possible to have a release with this merged?

@eltigerchino
Copy link
Member Author

It's in the next release #13277

@gyzerok
Copy link

gyzerok commented Jan 7, 2025

@eltigerchino yeah noticed that. Is it possible to cut it off already or does it wait for something?

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.

Page subscribe only works once after introducing $app/state
6 participants