Unintended page refresh with webpack5
See original GitHub issueWhat version of Next.js are you using?
10.2.0
What version of Node.js are you using?
12.14.1
What browser are you using?
Chrome
What operating system are you using?
macOS 11.2.3
How are you deploying your application?
debug mode(next dev)
Describe the Bug
When I turn on webpack5 and call internal api(/api/*) from page after first render, the page refreshes and logs Refreshing page data due to server-side change
. after refreshing once, it works fine as webpack4.
Expected Behavior
The page should not refresh on api call after first render.
To Reproduce
// News.tsx
const News = () => {
const { data } = useSWR("/api/!@#$", async ( ) => {
const res = await fetch('/api/!@#$');
const json = await res.json();
return json;
});
// ..
}
// /api/!@#$/index.ts
const requestHandler: RequestHandler = async (req, res) => {
const cacheManager = getCacheManager();
switch (req.method) {
case "GET": {
const cache = cacheManager.get(cacheKey);
if (cache) {
return res.status(200).json({ data: cache });
}
try {
const { data } = await NewsApi.get<Post[]>("/posts"); // wordpress rest api
cacheManager.set(cacheKey, data, 60 * 15);
return res.status(200).json({ data });
} catch (e) {
return res.status(500).end();
}
}
default:
return res.status(404).end();
}
};
export default requestHandler
// next.config.js
module.exports = {
future: {
webpack5: true,
},
}
``
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Unwanted page refresh with webpack5 in next js
When I turn on webpack5 and call internal api(/api/*) from page after first render, the page refreshes and logs Refreshing page data due...
Read more >Basic Features: Fast Refresh
Next.js' Fast Refresh is a new hot reloading experience that gives you instantaneous feedback on edits made to your React components.
Read more >React Fast Refresh — The New React Hot Reloader
A Comprehensive Guide to Using React Fast Refresh.
Read more >Tutorial: Create a Node.js and React app in Visual Studio
Webpack bundles JavaScript files so they can run in a browser, and can also ... You can install and update packages by using...
Read more >ReactJs Webpack and ASP.NET Core
wwwroot/js/app.js 7:4 Module parse failed: Unexpected token (7:4) You may ... You don't even need to refresh your browser; Webpack will do that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, I think we tracked this down to https://github.com/vercel/next.js/pull/25735 can you please update to
v10.2.4-canary.3
and see if you are still seeing the unexpected page reloading with webpack 5?I’m seeing something similar - a TON of fast refresh rebuilding or refreshing page data due to server-side change (despite me not touching keyboard, let alone the code), which leads to very annoying refreshes or redirects to
/
. This was not the case prior to our latest upgrade (we were running on Next 9.5.5 IIRC).EDIT: Maybe it’s my imagination or hope, but turning off Webpack5 with
future: { webpack5: false }
in config seemed to help a little.