Closed aldeed closed 5 years ago
This seems to be resolved. It was related to some sort of browser caching or cookie, perhaps from changing between environments. I'm not sure which, but one of the following should resolve if you see this:
I experience the same issue, but can't exactly tell the version as my fork of the starterkit diverges.
The error comes up when directly visiting /cart/checkout
, it works when being routed from another page.
And I think there actually are two versions of styled-components causing the issue:
The @reaction/components
module is using styled-components
3.3.3 while the starterkit is using 3.4.10.
That page is using a component which uses styled-components
: https://github.com/reactioncommerce/reaction-next-starterkit/blob/be9aac4ce1afbf266c9970f165ae451c23a976cd/src/components/CheckoutActions/CheckoutActions.js#L6
Somehow yarn didn't allow me to downgrade styled-components in the starterkit to 3.3.3 to see if that fixes it - Even when I explicitly installed styled-components@^3.3.3 and deleted my lockfile before, the new lockfile would have 3.4.10 again.
Installing the latest version of @reaction/components v0.65.2 also didn't fix it.
@janus-reith It may be true that there are multiple versions, but it's also true that whenever I see this error, if I log in it goes away. The cause is still a mystery to me, but it seems like logging in fixes whatever is causing the double load. It's possible it could have something to do with the server side rendering?
Probably it is related to SSR, as the error came up on direct page visits, but not when routed from somewhere else. There were cases when it just came as a warning, but in other cases it rendered the current page unfunctional. I couldn't really narrow it down yet.
As far as I got it, the way reaction-component-library is exported and used it still contains untranspiled styled-components
functionality, (and other stuff too) but that is a way that supports proper tree shacking and reduces overhead. (I'm not sure about the technical details here, but there seem to be other packages that also use styled-component on the inside but don't "leak" it, so that is my conclusion here.).
Therefore I wonder if it would be feasible to export styled-components from the component library and use it from there instead of directly including it in the starterkit? Actually there is very little code in the starterkit which is actually using it
I've investigated this more and passed it off to @willopez .
The error happens because both the styled-components commonjs entry point and the styled-components ES modules entry point get pulled into the bundle.
Why this happens is unclear, but it is likely either a webpack bug or something incorrect about the styled-components package.json
, or both.
The proximate cause is importing styled-components
from a .js
file in the app itself. As long as it's only imported from the Reaction component library, things are fine. As soon as you import once within any .js
file in the app, webpack seems to prefer the commonjs file for that import, and you end up with both being loaded on the page.
Some things we've identified to try:
styled-components
dependency to v4. This is a breaking change but might fix it if it's a package problem. We can release a new major version of the component library for this change.Attempts to resolved this issue:
Update the component library styled-components dependency to v4. This is a breaking change but might fix it if it's a package problem. We can release a new major version of the component library for this change. Tried, problem persists
I have created an isolated app the reproduces the issue:
https://github.com/willopez/double-styled-components
This rules out, SSR causing the problem.
@aldeed It seems that the way the components-library packages the components is at the root of this issue.
This does appear to be a Webpack bug. I created an even more minimal reproduction and created a Webpack issue here: https://github.com/webpack/webpack/issues/9329
@willopez and I did figure out a workaround, though, which is to use Webpack alias
to map all styled-components
imports explicitly to the .mjs
entry point. @willopez is going to do that for now until there is a real solution from Webpack folks.
Type: critical
Describe the bug Running latest
develop
on a fresh reset of the project, I'm seeing this error on the/cart/checkout
route:The page loads but shows the "Your shopping cart is empty" message even though it isn't empty.
There is also this warning:
I've checked the things they recommend and there don't appear to be two
styled-components
dependencies. I'm guessing a NextJS/SSR issue.I think this started with bumping the
@reactioncommerce/components
dependency to a version that exports EcmaScript modules. It would be good to find a solution that does not involve undoing that change since we need it for Webpack tree shaking, but it could be a quick-fix solution if we need one.To Reproduce Steps to reproduce the behavior:
Expected behavior Checkout page loads as normal
Desktop (please complete the following information):
UPDATE: Rolling back the component library fixes it as a workaround for now: