Skip to content

Conversation

@Algoinde
Copy link
Contributor

@Algoinde Algoinde commented Jan 8, 2023

Reference issue: #8398

This solves layouts always invalidating and rerunning load if they mention event.route, even if the route ID did not change, due to a wrong comparison in the code.

I have no idea how to write tests, but this should be simple enough.

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. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Jan 8, 2023

🦋 Changeset detected

Latest commit: 98bd50d

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

@Algoinde Algoinde changed the title Fix route invalidation comparison based on url and route, not on id [fix] route invalidation comparison based on url and route, not on id Jan 9, 2023
const url_changed = current.url
? url.pathname + url.search !== current.url.pathname + current.url.search
: false;
const url_changed = current.url ? id !== current.url.pathname + current.url.search : false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we sure the id, which serves as an unique identifier for caching from what I see, will always be an URL-type thing?

Copy link
Member

@dummdidumm dummdidumm Jan 9, 2023

Choose a reason for hiding this comment

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

the id in that instance (as its comment on hover suggests) is url.pathname + url.search - you can backtrack that variable to get_navigation_intent where it's computed as such

Copy link
Contributor Author

@Algoinde Algoinde Jan 9, 2023

Choose a reason for hiding this comment

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

Yeah, I know it is currently pathname + search - I'm just considering:

  • id name is closer to "route id" than to "URL", which it currently represents in essence - I think that's what caused the initial oversight
  • we are not sure if down the line that id will change to something else more specific, breaking this comparison once again.

So I opted to shed that id dependency - especially because url is still there being returned for its intended purpose, while id's purpose is something else entirely.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that id is probably a misleading name in this instance because of route.id, but that id cannot change during the cause of a route change (only if another route change is triggered as a result of it, at which point a new id will be computed). I think we can keep it as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I meant "change" as in "someone changes what is computed inside get_navigation_intent at some point due to a caching requirement change and overlooks this comparison due to destructuring, commits and it's borken again".

Thanks for merging!

@dummdidumm
Copy link
Member

Thank you!

@dummdidumm dummdidumm merged commit aa7f700 into sveltejs:master Jan 9, 2023
@github-actions github-actions bot mentioned this pull request Jan 9, 2023
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.

2 participants