question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unintended page refresh with webpack5

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
ijjkcommented, Jun 3, 2021

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?

4reactions
sMteXcommented, May 26, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found