-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
TypeError: Cannot read property 'key' of null on SSR #1728
Comments
This most likely is some configuration issue. Could you join our Slack and DM me there? We could discuss this further in a more prompt fashion. |
What was the resolution? |
@jkappers-ga I never got it working, and unfortunately ran out of time to keep trying. 😕 |
@ksweetie I couldn't get v10 to work, but downgrading to the following versions works for a Rails 6 app, ruby 2.7, and react-rails 2.6.1
|
I was using emotion The issue is that The codebase I'm working with is using Enzyme. If I I believe it's because of this: var EmotionCacheContext = React.createContext( // we're doing this to avoid preconstruct's dead code elimination in this one case
// because this module is primarily intended for the browser and node
// but it's also required in react native and similar environments sometimes
// and we could have a special build just for that
// but this is much easier and the native packages
// might use a different theme context in the future anyway
typeof HTMLElement !== 'undefined' ? createCache() : null); Specifically |
@KevinGhadyani-minted would you be willing to join our Slack and debug this with me? |
Joined. |
In case it's useful to help diagnose the issue, we had success using this post_install script as a patch. The SSR build in react-rails had /*
https://github.com/emotion-js/emotion/issues/1246#issuecomment-468381891
Monkey patch called postinstall to rename the browser property in ever @emotion/* package so it doesn't get used.
*/
const fs = require('fs')
const { sync } = require('glob')
sync('./node_modules/@emotion/*/package.json').forEach(src => {
const package = JSON.parse(fs.readFileSync(src, 'utf-8'))
const browser = package.browser
delete package.browser
if (browser) {
package._browser = browser
}
fs.writeFileSync(src, JSON.stringify(package, null, 2))
}) and in package.json "scripts": {
"postinstall": "node ./postinstall_patch.js"
} |
This solved our problems also, we needed to do some SSR using ReactJS.NET (run React components in ASP.NET) and had to build using webpack with target: "web" (the default). The monkey patch works but what also worked for me that doesn't require the monkey patch was setting this in webpack: resolve: {
aliasFields: ["module"] // Setting to "main" also works
}, This tells webpack to use the module or main field instead of the browser field. Could perhaps have effects on other packages though but worked for me... There is also a setting called Would be interesting to hear if setting the aliasField works for you also? |
Btw if you want a quick test repo this also happens inside next's |
@lucat1 this particular problem happens because |
Just want to confirm that in my case, while using Expo Web, this issue was resolved when I set Note that currently, due to misaligned tags on npm, running |
Thanks for mentioning that - it might be a bug in Changesets. Gonna report it over there when I dig a little bit more into this so I can report more details about the issue. EDIT:// I've diagnosed the issue in Changesets and started working on a fix: changesets/changesets#369 |
I believe that This is what other SSRing frameworks do, take a look at Gatsby: Closing this issue as it's not really actionable on our side. I would recommend reporting this to |
@jkappers-ga Thank you so much for the solution. You save my day. It took me many hours to fix this issue. I only need these packages:
Now, I can use Here is my project code. |
if you are using jsDom or someHow You have defined "document" globally on server side, emotion-element won't recognize that the context is server. |
@V1ruS32 Please open a new issue if that is causing a bug. If you do so, can you explain why |
@srmagura I don't think it's a bug. I was defining document globally on server side and I shouldn't do that. |
Current behavior:
Using the
css
property works on the client, but on SSR gives this error:Related issue: #1185
To reproduce:
The app I'm integrating this in is a Rails app using https://github.com/reactjs/react-rails so I made a repro with it. Hopefully you have ruby installed 🤞.
Here's a list of files I changed, otherwise it's a stock Rails app. Changing
prerender: true
tofalse
infoo.html.erb
should show that it's working on the client.Expected behavior:
Turning on SSR doesn't give an error.
Environment information:
react
version: 16.12.0emotion
version: 10.0.27The text was updated successfully, but these errors were encountered: