nuxt-swc icon indicating copy to clipboard operation
nuxt-swc copied to clipboard

`fetch` doesn't work on route change?

Open eggsy opened this issue 4 years ago • 1 comments

Hey! I'm glad to see an SWC module for Nuxt.js, I didn't expect it to see this fast but I wanted to try it out, and I guess I found an issue. I had nuxt-vite (which doesn't work for actual builds) and typescript-build module in my nuxt.config, I didn't disable nuxt-vite because it's already disabled for builds but I disabled typescript-build. Everything worked great, it was almost 3x faster... But I think it have issues with Nuxt's fetch hook on route changes. Here's my repository (I tried creating a Code Sandbox template but it didn't like my TypeScript interfaces).

Steps to reproduce

  1. Have at least 2 different routes.
  2. Make sure you use fetch() in one of these routes.
  3. Fetch something in the target route.
  4. Enter the route that you don't fetch anything and then move to the route you do the fetching.
  5. You'll see nothing, it doesn't fetch it.
  6. Reload the page and you'll see it fetches successfully.

P.S. This happened when I tried to view a blog post (on a statically generated website, using @nuxt/content) and in the route, I fetch data from Firebase. I reloaded the page I fetch data from Firebase, and it worked, but when I reloaded the content page, it failed to load the document.

What is causing this?

eggsy avatar May 21 '21 11:05 eggsy

Hi @eggsy and thank you fir your feedback.

A reproduction should be minimal so we can easily see what's causing the issue.

Actually with SSG, the fetch and asyncData are mocked and not called anymore so I am not sure if this is related to SWC module.

atinux avatar Aug 12 '21 11:08 atinux