New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
styled-component overridden on hot reload #4068
Comments
I have the same bug, with a different setup. I have a monorepo with two folders :
I have it in an example repo : https://github.com/lucleray/ssr-ui-library When I update the background color for example, in the ui folder, and save the file, the page updates. |
Is this anything to do with the injection order of the style sheets in |
@ianregister No, the order of the injection in The problem is that the server and the client don't render the same code for stylesheets |
I have the same bug and it is not only on styles. Hot reload will pick up the changes, but refreshing browser does not. I have to run server again (node server.js) in order to pick up the latest update. I am using next@6.0-canary.3, react 16.3 and express for the server. |
@lucleray, try this: Make sure you have Think that this is just a configuration issue you are facing. package.json "babel": {
"env": {
"development": {
"presets": ["next/babel"],
"plugins": [
[
"styled-components",
{
"ssr": true,
"displayName": true
}
]
]
},
"production": {
"presets": ["next/babel"],
"plugins": [
[
"styled-components",
{
"ssr": true,
"displayName": false
}
]
]
}
}
} |
@tvthatsme I added You can check here : I'm not sure it is configuration (webpack configuration), or a bug somewhere. |
having similar issue where any edits to a component (non styles related) will cause an error "Warning: Prop @sea129 were you able to fix? |
Lol, having the same issue here. @valeeum were you able to solve it? |
I did a bit of research on this issue, and I think it might be link some sort of "webpack caching". I use the code here as an example of the issue : https://github.com/lucleray/ssr-ui-library The On the server-side, the bundle does not include the It appears like this in the /***/ "../ui/bundle.js":
/*!***********************!*\
!*** ../ui/bundle.js ***!
\***********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var styled = _interopDefault(__webpack_require__(/*! styled-components */ "../node_modules/styled-components/dist/styled-components.browser.esm.js"));
const UiButton = styled.button`
background: black;
`;
exports.UiButton = UiButton;
/***/ }), On the other hand, in the /***/ "@monorepo/ui":
/*!*******************************!*\
!*** external "@monorepo/ui" ***!
\*******************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = require("@monorepo/ui");
/***/ }), What is weird is that If I change the background color of the button in the It solved it by configuring webpack to treat I would still like to understand what's happening 🤔 |
|
Ok, that makes sense. So the issue is that the hot-reloader doesn't reload the code changes in external dependencies, on the server-side, right ? In the example I shared, I expect my code changes to be loaded both on client (which is the case) and server (which is not the case) side in development mode. |
Exactly, we only delete full paths from the require.cache. |
How do you think I could solve this @timneutkens ? Should I remove |
It might be as easy as using https://github.com/martpie/next-plugin-transpile-modules to enable module compilation. |
@timneutkens Why was this closed? this issue still exists on the latest version |
Still having this issue as well |
Im still having this issue too |
Ditto too here |
Also having this issue Edit (solution): This issue is related to not having the babel config setup correctly. If you look at the official example of NextJS with styled-components you'll notice they have a {
"presets": ["next/babel"],
"plugins": [["styled-components", { "ssr": true }]]
} Then you must add this plugin to the devDependencies in your "devDependencies": {
"babel-plugin-styled-components": "^1.8.0"
}, Then run your install command, P.S: Be sure to only have one tab open for your localhost dev work! |
ok people. here is the solution. create an _document.js in root of directory and add this.
then also create a custom app in pages directory, _App.js and add:
you're all set |
This works, Thanks |
Unfortunately, it's still an issue. I am witnessing something weird though: If you have
on the initial load it's red, when you change it to
it gets ignored, text becomes black, no styles. So when you add a new style via HMR it gets ignored, but on initial render it's placed in cache, and if you use this style later via HMR it's gonna work. So it's not delivered to browser properly on HMR? I don't have knowledge on SC and Next.js internals, so those are just my guesses. EDIT: |
not sure how relevant this info will be, but how i fixed it for myself is i followed the example from next repo and integrated the missing bits a pieces |
I was using next.js and @maxmckinney solution worked for me. Just make sure you have configured the This was my {
"presets": [
[
"next/babel",
{
"styled-jsx": {
"plugins": [
"styled-jsx-plugin-postcss"
]
}
}
]
],
"plugins": [
[
"styled-components",
{
"ssr": true
}
]
]
} |
This issue will occur if you're cloning and building on one of the Next.js examples that don't have the same |
In my case ,just add _app.js and _document.js file under pages floder,it work fine.
|
How should I use it in the Material-UI? |
Thanks, it worked here! |
For ones going through the same issue, this worked for me. |
I was having the exact same issue and it was resolved by doing: npm i babel-preset-next
npm install --save -D babel-plugin-styled-components and adding this to .babelrc file: {
"presets": ["next/babel"],
"plugins": [["styled-components", { "ssr": true }]]
} |
I am not using babel but SWC hence I don't have the .rc file. Since the issue is still present. Can anyone suggest what configuration will be needed and where to fix this issue? |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Expected Behavior
My page contains this very basic code:
When I refresh the page, I expect the Title to be of color pink
Current Behavior
The first time the page is built, the title does appear as pink. When I refresh the page, the pink color is no longer respected.
If I change the color in the code to anything else, and save the file, then the page will update. But again, upon refreshing, the changes are lost again. I have no clue what might be causing this. Any help is appreciated.
Your Environment
The text was updated successfully, but these errors were encountered: