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.

CSS is reset on route change in production build

See original GitHub issue

Bug report

Describe the bug

When you navigate to a different route in Next.js 10.0.0 module specific css is reset. This is problematic, because I keep the component mounted for a bit longer to do some animations with framer-motion. In Next.js 9 this was not an issue.

Edit: By the comments it seems like this bug first occured in 9.5.5

To Reproduce

Here is a very basic example. If you run the app in dev mode it works fine, but the production build doesn’t. The css is immediately removed if you click on the link. https://v10-test.vercel.app/

Source code: https://github.com/mxmtsk/v10-test

To keep the page component mounted until the animation is finished, I’m using AnimatePresence from framer-motion

Edit: Here’s the same example using Next 9.5.1, where everything works fine: https://v10-test-git-v9.mxmtsk.vercel.app/

Expected behavior

CSS should not be reset.

System information

  • OS: macOS
  • All Browsers
  • Version of Next.js: 10.0.0
  • Version of Node.js: 12.13.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
organdonor47commented, Nov 4, 2020

same issue as #17464

2reactions
damianslonskicommented, Oct 27, 2020

I have the same issue, but even with Next 9.5.5. 🤔 Probably the reason is production code splitting for CSS Modules. E.g. global styles & styled-components work fine.

https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css

In production, all CSS Module files will be automatically concatenated into many minified and code-split .css files. These .css files represent hot execution paths in your application, ensuring the minimal amount of CSS is loaded for your application to paint.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Production build overrides my style in .css node - Stack Overflow
I have problems with webpack.config.js I need this put on the root directory or webpack module directory? In package.json is webpack not ...
Read more >
Building for Production - Vite
cache.reset() needs to be called at buildStart for build watch mode to work correctly in this case. Rebuild on files changes #. You...
Read more >
Styling - Remix
When changes are made to the source file, sass will regenerate the CSS file automatically. Generated CSS files will be stored in the...
Read more >
Client-Side Routing In Next.js - Smashing Magazine
js app consists of route-able pages (route handlers or routes) interconnected by a router. Next.js has built-in support for routing that can be ......
Read more >
React - Parcel
Parcel works great for building single or multi-page React applications. ... and other types of values, its state will be reset whenever it...
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