kit icon indicating copy to clipboard operation
kit copied to clipboard

Data Updates for `/post/[slug]`, But Not For `/post`

Open manunamz opened this issue 5 months ago • 7 comments

Describe the bug

If you use the same server load function for a root route and a slug route, the root route loses the ability to navigate to slug routes once navigated to.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-wbh3iw?file=src%2Froutes%2Fpost%2F%5B%5Bslug%5D%5D%2F%2Bpage.server.js

If you click on "first post" and then "posts" in the header, it works fine. If you click "posts" then "first post", you'll see how the content does not update when you click on "first post" this time. The other routes work as expected.


It is noteworthy that the file structure in the example is:

/src
  /lib
    /routes
      /post
        /[[slug]]
          +page.server.js
          +page.svelte

But this bug persists for different variations that lead to the same routing structure. For example:

/src
  /lib
    /routes
      /post
        +layout.server.js
        +layout.svelte
        +page.svelte
        /[slug]
          +page.svelte

Etc.

Logs

There is no output to either the logs in the terminal on http://localhost:5173/ or in the browser's console.

System Info

System:
    OS: macOS 14.2
    CPU: (8) arm64 Apple M1
    Memory: 56.66 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.2.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.6.6 - /opt/homebrew/bin/npm
    pnpm: 7.8.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Brave Browser: 119.1.60.118
    Chrome: 120.0.6099.129
    Edge: 120.0.2210.61
    Safari: 17.2
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.1.0
    @sveltejs/kit: ^2.0.0 => 2.0.6
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.0.1
    svelte: ^4.2.7 => 4.2.8
    vite: ^5.0.3 => 5.0.11

Severity

annoyance

Additional Information

Discord Post

manunamz avatar Jan 27 '24 00:01 manunamz

Hi,

Yes invalidation is completely broken in SvelteKit, buckle up :

https://github.com/sveltejs/kit/issues/11635 https://github.com/sveltejs/kit/issues/11696 https://github.com/sveltejs/kit/issues/11663 https://github.com/sveltejs/kit/issues/11446 https://github.com/sveltejs/kit/issues/10209 https://github.com/sveltejs/kit/issues/10123 https://github.com/sveltejs/kit/issues/10457 https://github.com/sveltejs/kit/issues/10359

Unfortunately the team will read your issue and pretend it doesn't exist just like the other ones.

Meanwhile, features like generating random images of gooses receive a lot of care and attention.

gterras avatar Jan 27 '24 05:01 gterras

Hi,

Yes invalidation is completely broken in SvelteKit, buckle up :

#11635 #11696 #11663 #11446 #10209 #10123 #10457 #10359

Unfortunately the team will read your issue and pretend it doesn't exist just like the other ones.

Meanwhile, features like generating random images of gooses receive a lot of care and attention.

Sorry this flew under the radar. I've just forwarded these issues to the team. Thank you for helping to compile a list of these issues.

Personally, I'll try to have a look at these this week when I can, usually after work and other commitments. Recently, I've been giving myself a bit of a break as I've been feeling burnt out from looking at code at work then looking at more code after work so I haven't been looking at any issues in depth.

eltigerchino avatar Jan 27 '24 16:01 eltigerchino

Someone suggested on discord some workarounds for this particular error -- for example:

export const load = async ({ params: {slug} }) => {
  const post = posts.find((post) => post.slug === slug);
  return { post: post ?? posts[0] };
};

I tried it and it does seem to work! As the author points out, it "seems like kit just doesn't see the dependency on slug without explicit reference".

I will leave this ticket open though, as the original issue is still true and it seems to be symptomatic of deeper issues. Hopefully some of this will help with debugging.

manunamz avatar Jan 27 '24 21:01 manunamz

@gterras , could invalidation also be causing this issue https://github.com/sveltejs/kit/issues/6315 ?

(Not quite sure where to put this question...So here it goes)

manunamz avatar Jan 29 '24 18:01 manunamz

@gterras , could invalidation also be causing this issue #6315 ?

Not sure what you mean this looks like a purely conceptual issue?

gterras avatar Jan 30 '24 13:01 gterras

I'm not able to reproduce this issue by following the instructions. The pages load fine in both orders of navigation. Can you re-confirm if you're still seeing this issue?

eltigerchino avatar Feb 16 '24 18:02 eltigerchino

https://github.com/sveltejs/kit/pull/11870 just fixed a lot of the issues with invalidation, so can you test to see if you're still having issues with 2.5.1?

benmccann avatar Feb 22 '24 17:02 benmccann