-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Bug: Styled-components are unstyled using React Server Components (the component contains all the necessary props) #23126
Comments
Updated dependencies of the reproduction repo to React 18. |
I don't think there is a bug in React here. styled-components would need to add support for Server Components — I don't think it's expected to "just work" with the current approach. It would be good to file an issue in the styled-components repo for this discussion. I think the React 18 streaming guides like reactwg/react-18#110 and reactwg/react-18#108 might be good starting points, though I think Server Components will probably require something additional to that. I'll need to check with the team to answer this. Regardless, there is no bug in React related to this. |
With regard to the react-server-components error (but unrelated to the Hydrogen one), this is due to an issue with the Babel config in the demo apps. Inside react-server-components-app you have const register = require('react-server-dom-webpack/node-register');
register();
const babelRegister = require('@babel/register');
babelRegister({
ignore: [/[\\\/](build|server|node_modules)[\\\/]/],
presets: [['react-app', {runtime: 'automatic'}]],
plugins: ['@babel/transform-modules-commonjs'],
}); This is the same setup as @gaearon 's SSR demo at https://codesandbox.io/s/kind-sammet-j56ro and also the server-components-demo. Unfortunately the babel config on both of these apps is pretty flakey: e.g. if you open https://codesandbox.io/s/kind-sammet-j56ro and change App.js to have the following: export default function App({ assets, test = ["a", "b"] }) {
const [a, b] = test;
console.log(a, b); You will see: https://github.com/browserslist/browserslist#browsers-data-updating
internal/modules/cjs/loader.js:1102
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /sandbox/node_modules/@babel/runtime/helpers/esm/slicedToArray.js This means babel can't process I guess a different babel config is needed here, rather than just the react-app preset plus @babel/transform-modules-commonjs. I can't find much else referencing this issue, I'll try remember to post back here if I find any solution. @gaearon if you've made any demos since then that improves this setup, please let me know :) |
I was able to modify the babel config to load commonjs modules on the server, details in this PR: |
Context
Its seems that React Server Components do not Support CSS-in-JS at the moment.
Related to an issue in the
Hydrogen Framework by Shopify
: Shopify/hydrogen#398Describe the bug
Hello, it seems I have encountered a bug using styled-components from external library.
The basic setup from the React Server Components can't compile, because of the package extension (see spoiler with full log below). This error seems weird :
Once the component is loaded in front-end, it's not flagged as "component" in react dev tools (other Hydrogen elements are) and has no CSS applied.
To Reproduce
Reproduction Repository
yarn workspace react-server-components-app add @test/ui
<TestButton>Yo !</TestButton>
Expected behaviour
The site should compile and the button should have CSS props and shoudn't be unstyled.
Logs
Inside React Server Components application with button : error starting with
yarn start-rsc
Inside hydrogen app : console.log(TestButton.componentStyle.rules[0]({variant: 'primary'}))
Additional context
In the reproduction repo, the same component from same build is used in:
Versions & System
OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 393.64 MB / 15.32 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Thx for your time !
The text was updated successfully, but these errors were encountered: