vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.09k stars 27k forks source link

with-msw: Next.js doesn't show changed mock-data without a restart of dev server #45250

Open overtune opened 1 year ago

overtune commented 1 year ago

Verify canary release

Provide environment information

Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000 Binaries: Node: 16.19.0 npm: 8.19.3 Yarn: 1.22.18 pnpm: 7.25.1 Relevant packages: next: 13.1.6-canary.1 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0

Which example does this report relate to?

with-msw

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Changes to msw mock files aren't displayed in next.js site. Test to run yarn dev, look at the site (it displays the book "Lord of the Rings"). Go to mocks/handlers.ts and change the mock-data (like changing the title of the book). In the terminal you'll see:

wait  - ccompiling...
event - compiled client and server successfully in 91 ms (370 modules)

But in the browser the old title is still being displayed. Even on a hard refresh of the browser. The only way to get the updated mock data to be displayed is by stopping the dev-server and restart it with yarn dev.

We noticed this behaviour in some projects when we updated to Next.js 13. When we tested this example (with-msw) out, we noticed it had the same problem.

Is there some caching mechanism in Next.js 13 that is the problem here?

Expected Behavior

We expect that changing mock-data while running the dev server should cause a fast refresh in the browser with the updated data being visible. (Or at least that the data is updated when doing a refresh of the browser window).

To Reproduce

  1. Install this example npx create-next-app --example with-msw with-msw-app
  2. Start in dev-mode yarn dev
  3. Edit mocks/handlers.ts, change like the title of the book.
  4. The browser doesn't display this update
mizdra commented 1 year ago

I think this is related to https://github.com/mswjs/msw/issues/1389.

ryanolson-aumni commented 10 months ago

Anyone?

Edit by maintainers: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!