-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
4.0 - [SSR] ServerStyleSheet's collectStyles
fails to collect styles from symlinked modules
#2322
Comments
collectStyles
fails to collect styles from symlinked modulescollectStyles
fails to collect styles from symlinked modules
You need to deduplicate your See the FAQ on the website for instructions with various build tools: https://www.styled-components.com/docs/faqs#why-am-i-getting-a-warning-about-several-instances-of-module-on-the-page Hope that helps! |
@mxstbr, I could be misunderstanding, but I've read that FAQ a few times prior to posting here and it doesn't cover the issue during the SSR pass, since it doesn't involve Webpack or anything client-side / build-tool related, and additionally, ya'll have a large banner: Which is exactly the problem that we're facing and the issue describes. Deduping doesn't work with There is a If this is a hard limitation around All that said, if there's nothing we can do then there's nothing we can do 👍 |
It looks like we're going to have to refactor our apps and their dependencies under a yarn workspace to get around this limitation. |
In the OP you said:
Aren't your React component libraries built with webpack or rollup? How are they created? |
We use babel to compile out our sources into a dist folder. |
Can you try marking That makes development impossible (😅) but let's figure that out afterwards if it works. |
That's how we currently have it (this is SC 3, from Which is then read into our other component library: Which is then merged all together into our app server: In the top two instances we install it as a |
Yup, that works since the only instance of I guess a somewhat flimsy solution would be to write a script that deletes the folder from target locations, but yeah 😄 |
Yay! So now the question is how to fix development 😅 |
@mxstbr - Should this issue be reopened, or are there docs that could be added to better communicate the issue? For non-trivial applications moving to a workspace can be fraught with problems. |
Well it's not an issue with the library, more an environmental restriction. For that reason I would not reopen this issue. If you feel there's a deficiency in our docs though, I'd welcome a PR there. |
@damassi We've just started running into the same situation with our project. It works fine when compiling with babel and then adding |
My guess is the Babel plugin needs to be deduped too
…On Tue, Mar 5, 2019 at 2:44 PM Kyle Nieber ***@***.***> wrote:
@damassi <https://github.com/damassi> We've just started running into the
same situation with our project. It works fine when compiling with babel
and then adding styled-components as a peerDependency and pulling down
the published code from npm, however it isn't working when linking. I even
looked at your component library repo, and it appears we're doing things
very similarly. Did you all find a way to get this working with local
development? Did using a yarn workspace work?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2322 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAiy1rShzqO_NnaXFUUn_LplHX17C67Tks5vTtcmgaJpZM4Z9oQx>
.
|
@knieber - A Our work around was to setup this command in our main host app, which is a band-aid:
This required us to change our workflow quite a bit. Before we'd write most of our UI code in React StoryBooks and then in the host app check things in parallel. Now we can only work in one app at a time. Also, if a sub-dep depends on another dep that contains styled-components and everything is linked together back to the main app, things seem to error out when I remember a while back Emotion handled this SSR + yarn linking problem by allowing the sharing of a context, but I'm not sure what the status is on that. |
@probablyup @damassi appreciate the quick responses! I'm going to be trying both. Currently the steps in that script aren't working for me when using |
This is indeed a common workflow for apps and teams. It worked well with Styled Components 3 so I'm hopeful that a more formal solution can be discovered at some point. Thanks for looking into it @knieber! |
Ok @knieber, @probablyup - I think I've found a potential solution via require-control. Hasn't been extensively tested, but looking good so far: const { setAliases } = require("require-control")
const path = require("path")
setAliases({
"styled-components": path.resolve(
path.join(__dirname, "../node_modules/styled-components")
),
}) Obviously this isn't totally ideal as it's doing some require hacking but seems sufficient for our use-cases. Let me know if this works for you. |
Want to note that I discovered |
@damassi Sorry, just now getting back to this. Actually, I'm now having a problem with Note: a temp workaround that we found was using Yalc to publish npm packages locally onto your machine, without actually publishing to npm. It's far less than ideal, but thought I'd spread the love. |
Finally figured out by babel dupe-ing issue (component lib had a babel-core 6 dependency from storybook) and just got back to the styled-components instancing issue. The |
Yeah! Our team was psyched to discover it. I should probably open a PR to update SC's docs. |
We would love a PR @damassi!!! |
I've opened a pr in order to add this info to npm link issues on FAQ. Special kudos to @damassi for his amazing investigation in this issue. You saved my day dude! |
@knieber @damassi Im struggeling a bit with the same setup now. I have a component library we want to use for web and SSR, which is styled with styled components. We run webpack and babal on this library so we can import it around. When collecting styles from the SSR app, there is no CSS available. When collecting styles from the component library, the CSS is coming out when run on the server side, crashes when running in the browser of course. Im just not seeing why this require would help for me? As they are already sharing packages. Is it something to do with the webpacking im doing that the styles are dissapearing when loaded in an SSR environment? Because after the client is loaded by next.js, the styles are also applied. Im a bit lost :( |
I have a reproducable setup here, if anyone are able to get any of the packages, preferebly styled-components, to work here. With no FOUC, I would be super happy! |
@mxstbr any thoughts, base on this repo? |
For those who're using lernajs adding styled-components as |
well, for me, adding What worked for me was creating a I know this is an ugly solution but this is the only one that worked for me. |
What worked for me is aliasing styled components to the the instance I need. Without it styles probably got compiled with worng instance of SC.
Hope this will help somebody (me in future for example) |
I was facing similar issue where the myApp was not collecting styles from the symlinked module. I was able to resolve the issue by adding styled-components as a peer dependency in my component library and then doing npm link myApp/node_modules/styled-components from my library's root directory. |
I've recently begun a styled-components 4.0 upgrade on our apps but ran into a hard blocker around SSR, local development and symlinked modules using
yarn link
, which differs from v3.Here's a repo reproducing the issue: https://github.com/damassi/styled-components-ssr-issue
Scenario:
Our main website is a complex host environment (shell) that imports React components (Apps) from other NPM modules. When the host receives a route request it performs an SSR render
and sends a payload down to the client, which is then rehydrated on mount.
When working from a local dev environment each of these modules is symlinked via
yarn link
so dependency changes don't need to be published to npm after each change.Because of v4's new static context API, its no longer possible to
yarn link
submodules and preserve SSR rendering locally as different styled-component modules are now managing their own list of styled-components to render. From the host app it appears as though there's nothing to extract because no styled components have been created in that scope.Due to application complexity, it's fairly common to run into SSR reconciliation issues and so disabling SSR during local development is not an option. Is there a way to work around? This appears to be a regression from v3 since symlinked modules + SSR behaved well.
(Note that the
--preserve-symlinks
suggestion from this thread doesn't seem to work, and we're not working from a monorepo like Lerna.)Update:
Was able to resolve via
require-control
; see this message below.The text was updated successfully, but these errors were encountered: