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

Regression in v2: parent() returns old data even after the parent was invalidated using invalidate() #11696

Closed
kyngs opened this issue Jan 20, 2024 · 16 comments
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Milestone

Comments

@kyngs
Copy link

kyngs commented Jan 20, 2024

Describe the bug

This is hard to explain, but I'll do my best.
Imagine the following route structure:

routes/
├─ +page.svelte
├─ +layout.ts
├─ [id]/
│  ├─ +page.svelte
│  ├─ +page.ts
├─ add/
│  ├─ +page.svelte

The root page shows a basket of fruits, which is loaded from an API in the root +layout.ts. It also includes a button that links to the add page.
The add page includes a button that adds fruit to the basket by posting to the API. After doing so, it invalidates the root +layout.ts load function and then navigates to the root page.
The [id] page only verifies whether a fruit with such an ID exists in the basket. It does that using the +page.ts load function, which fetches the parent using await parent() and then observes, whether a fruit with such an ID is in the parent data.

Now, let's imagine I do this:

  • I navigate to the add page
  • I press the button to add a fruit
  • I get redirected to the root page, where the fruit is now listed.
  • I click the fruit, which redirects me to /[id] with the fruit id.
  • However, the page tells me that no such fruit exists.
  • I click back and navigate to the root page, which now does not list the fruit at all.
  • I refreshed the page, and now everything works.

Here's a video where I do that:

simplescreenrecorder-2024-01-20_22.15.00.mp4

However, when I downgrade to sveltekit v1, or use invalidateAll() instead of invalidate(), everything works correctly, and the parent() function returns correct data.

Reproduction

SvelteKit v2: https://stackblitz.com/edit/stackblitz-starters-dp4avt?file=src%2Froutes%2F%5Bid%5D%2F%2Bpage.ts
The issue here is easily reproducible as shown in the video

SvelteKit v1: https://stackblitz.com/edit/stackblitz-starters-et87cn?file=src%2Froutes%2F%5Bid%5D%2F%2Bpage.ts
The issue is not reproducible, everything works as expected. See the video:

simplescreenrecorder-2024-01-20_22.24.28.mp4

And as a bonus, SvelteKit v2 using invalidateAll(): https://stackblitz.com/edit/stackblitz-starters-4rh3gc?file=src%2Froutes%2Fadd%2F%2Bpage.svelte
The issue is also not reproducible, everything works as expected.

Logs

Not applicable

System Info

System:
    OS: Linux 6.6 Arch Linux
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 35.83 GB / 62.70 GB
    Container: Yes
    Shell: 3.7.0 - /usr/bin/fish
  Binaries:
    Node: 18.18.2 - /usr/bin/node
    Yarn: 1.22.21 - /usr/bin/yarn
    npm: 10.2.5 - /usr/bin/npm
    pnpm: 8.14.0 - /usr/bin/pnpm
    bun: 1.0.18 - /usr/bin/bun
  Browsers:
    Chromium: 120.0.6099.199
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.1.1 
    @sveltejs/kit: ^2.0.0 => 2.4.1 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.0.1 
    svelte: ^4.2.7 => 4.2.9 
    vite: ^5.0.3 => 5.0.12

Severity

blocking an upgrade

Additional Information

PS: Even though using invalidateAll is a workaround, I've decided to use the "blocking an upgrade" severity as rerunning all the load functions is not acceptable.
I hope I explained the issue well, if you have any questions, ask me.

@gterras
Copy link

gterras commented Jan 22, 2024

This bug is very real but hasn't been acknowledged by the team yet, see #11268 (comment).

And also :

#11663
#11446
#10209
#10123
#10457
#10359

@kyngs
Copy link
Author

kyngs commented Jan 22, 2024

This bug is very real but hasn't been acknowledged by the team yet, see #11268 (comment).

And also :

#11663 #11446 #10209 #10123 #10457 #10359

Thanks for the information! I hope they tackle this soon as this is a very severe issue for me.
I'm not really experienced in nodejs, so I have no idea where to start if I were to fix this on my own.

@kyngs
Copy link
Author

kyngs commented Jan 22, 2024

I'm kinda spooked this is a half year old issue tho

@gterras
Copy link

gterras commented Jan 22, 2024

I'm kinda spooked this is a half year old issue tho

Partial invalidation has never been fully functional in SvelteKit, even pre 1.0. I suspect none of the maintainers know how to fix it.

@kyngs
Copy link
Author

kyngs commented Jan 22, 2024

I'm kinda spooked this is a half year old issue tho

Partial invalidation has never been fully functional in SvelteKit, even pre 1.0. I suspect none of the maintainers know how to fix it.

Hasn't it? Tbh I've never had any issues with it in v1

@gterras
Copy link

gterras commented Jan 22, 2024

Hasn't it? Tbh I've never had any issues with it in v1

You most likely had the double invalidation bug with SK1 without realizing it #10359 since they seem heavily related, but at least it wasn't app breaking.

@kyngs
Copy link
Author

kyngs commented Jan 22, 2024

This bug is very real but hasn't been acknowledged by the team yet, see #11268 (comment).

And also :

#11663 #11446 #10209 #10123 #10457 #10359

@Rich-Harris I'm sorry for mentioning you, as I'm sure you have a lot of work. But you're the author of the original PR which @gterras suspects to be the culprit. Unfortunately, the issues with invalidating have been here for almost half a year, and they seem to progressively get worse. Could you please take a look into this?

@kyngs
Copy link
Author

kyngs commented Jan 23, 2024

This bug is very real but hasn't been acknowledged by the team yet, see #11268 (comment).

And also :

#11663 #11446 #10209 #10123 #10457 #10359

I can confirm that the PR is causing the issue, removing the invalidated.length = 0; does fix my issue, but it might cause a new one.

@kyngs
Copy link
Author

kyngs commented Jan 23, 2024

@stalkerg hey! Seeing that you liked the issue, do you have the same problem?

@stalkerg
Copy link
Contributor

@kyngs not yet; I did it to improve visibility. Unfortently I have no time now to go deeper and fix it. If nobody fixes it next week, I will try to help.

@hmnd
Copy link
Contributor

hmnd commented Feb 7, 2024

I'm experiencing the same issue. In my case, I have a page that calls parent() and an invalidate call in the layout that redirects to /login when an auth check fails. Previously that worked just fine, but now it gets stuck showing the same page, but loaded with /login's page data.

@kyngs
Copy link
Author

kyngs commented Feb 7, 2024

@kyngs not yet; I did it to improve visibility. Unfortently I have no time now to go deeper and fix it. If nobody fixes it next week, I will try to help.

Seems like noone fixed it yet, could you please look into it?

@denjpeters
Copy link

Is there any movement on this? This is a fairly serious regression, and is preventing us from moving to SK v2.

I did create a simple GitHub project that demonstrates the problem, if that helps... https://github.com/denjpeters/SK2Test

@kyngs
Copy link
Author

kyngs commented Feb 8, 2024

Is there any movement on this? This is a fairly serious regression, and is preventing us from moving to SK v2.

I did create a simple GitHub project that demonstrates the problem, if that helps... https://github.com/denjpeters/SK2Test

Unfortunately, there is no movement on this.

@gterras
Copy link

gterras commented Feb 9, 2024

Tried to start something here #11819

@eltigerchino eltigerchino added the bug Something isn't working label Feb 16, 2024
@eltigerchino eltigerchino added this to the soon milestone Feb 16, 2024
@eltigerchino eltigerchino added the p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. label Feb 16, 2024
@dummdidumm
Copy link
Member

Closing as duplicate of #11446

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants