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

Route invalidation check is broken due to comparing to intent id, not url and route #8398

Closed
Algoinde opened this issue Jan 8, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Algoinde
Copy link
Contributor

Algoinde commented Jan 8, 2023

Describe the bug

When investigating the invalidation mishappenings in my project, I came upon these lines:

https://github.com/sveltejs/kit/blame/4ff91b0e98f571b5e3b0f6e4fc30481426fd6255/packages/kit/src/runtime/client/client.js#L712

The id in that function is taken from intent that is returned from get_navigation_intent. The id in this intent from what I see is used as a cache key. It is, in fact, a URL, not a route ID:

function get_navigation_intent(url, invalidating) {
	if (is_external_url(url, base)) return;

	const path = decode_pathname(url.pathname.slice(base.length) || '/');

	for (const route of routes) {
		const params = route.exec(path);

		if (params) {
			const id = url.pathname + url.search;
			/** @type {import('./types').NavigationIntent} */
			const intent = { id, invalidating, route, params: decode_params(params), url };
			return intent;
		}
	}
}

Later this is used in the aforementioned comparison:

//id == '/whatever/url/you/have/1/1231/'
//current.route.id == '/[page]/url/[who]/[verb]/[id]/[subid]'
const url_changed = current.url ? id !== current.url.pathname + current.url.search : false;
const route_changed = current.route ? id !== current.route.id : false;

As a result of this, route_changed is always true, which I think will invalidate any layouts all the time if they happen to have something that accesses event.route.id in the stack.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-4tqaxj?file=src/routes/stuff/+layout.js

Switch between about and notAbout in the header.

route.id

System Info

System:
    OS: Linux 4.4 Ubuntu 22.04 LTS 22.04 LTS (Jammy Jellyfish)
    CPU: (12) x64 AMD Ryzen 5 3600X 6-Core Processor
    Memory: 7.40 GB / 31.95 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.106 => 1.0.0-next.106
    @sveltejs/kit: ^1.0.0-next.589 => 1.0.0-next.589
    svelte: ^3.54.0 => 3.55.0
    vite: ^4.0.0 => 4.0.3

Severity

annoyance

@Algoinde Algoinde changed the title Route invalidation check is broken due to strangely named parameter inside intent returned from get_navigation_intent Route invalidation check is broken due to comparing to intent id, not url and route Jan 8, 2023
@dummdidumm dummdidumm added the bug Something isn't working label Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants