Skip to content
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

document is not defined with react-on-rails #1407

Closed
brandoncc opened this issue Jun 20, 2019 · 11 comments
Closed

document is not defined with react-on-rails #1407

brandoncc opened this issue Jun 20, 2019 · 11 comments

Comments

@brandoncc
Copy link

brandoncc commented Jun 20, 2019

Current behavior:

The documentation says that server side rendering works with no configuration needed if you install @emotion/core in a React app. I am getting document is not defined during the SSR.

I am using @emotion/styled, not css or jsx, I'm not sure if that could be where my problem is?

import * as React from 'react';
import styled from '@emotion/styled';

const Container = styled.div(
  {
    marginTop: 6,
    position: 'relative'
  },
  props => props.css
);

The error looks to be coming from a createCache method.

To reproduce:

I can create an example app if needed but I don't have one handy.

Expected behavior:

The page should render.

Environment information:

  • react version: 16.8.0
  • emotion version: 10.0.10
@Andarist
Copy link
Member

How so you build your server? Webpack?

@brandoncc
Copy link
Author

Yes, using webpacker via rails

@brandoncc
Copy link
Author

brandoncc commented Jun 20, 2019

I saw the other issue about cache breaking some static site generators....I don't think I have the same problem though. I have two bundles, one if which is for the server and uses renderToString. That is where I am having this error.

@xtroncode
Copy link

I am facing the same issue with ReactJS.net

@Andarist
Copy link
Member

You should use target: ‘node’ in your webpack config

@brandoncc
Copy link
Author

I don't think I can change that with webpacker :-/

@brandoncc
Copy link
Author

Also, my code is running in the browser except that one bundle, don't I want it targeting the web?

@Andarist
Copy link
Member

Well, I dont know how your bundles are structured - but in general client-side bundles are not the same as your SSR entry point, so you should have 2 separate builds.

@Dangoo
Copy link

Dangoo commented Jul 27, 2019

@Andarist I have a similar issue, but I'm forced to use target: webworker in order to deploy my code to cloudflare. In that mode neither document nor process are allowed.

Maybe also related: #1246

@Andarist
Copy link
Member

Andarist commented Sep 7, 2019

If you specify target as webworker the bundler should use default entries which have document access guarded.

If this is not working properly you would have to prepare a repro case that would showcase the behavior and which would be easy to investigate.

@Andarist
Copy link
Member

Closing this because we have not received a repro case since September. It's also definitely a problem with used tooling or its configuration - not something we can fix in Emotion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants