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 #102

Closed
hennessyevan opened this issue Jul 18, 2019 · 7 comments · Fixed by #115
Closed

document is not defined #102

hennessyevan opened this issue Jul 18, 2019 · 7 comments · Fixed by #115

Comments

@hennessyevan
Copy link
Collaborator

Description

v.0.3.0 in a razzlejs build with ssr balks when I add remirror editor to the mix. The renderer is working just fine.

ReferenceError: document is not defined
    at createCache (/Volumes/Data/razzle-demo/node_modules/@remirror/react-ssr/lib/dist/react-ssr.esm.js:1191:1)
    at Module.../node_modules/@remirror/react-ssr/lib/dist/react-ssr.esm.js (/Volumes/Data/razzle-demo/build/webpack:/node_modules/@remirror/react-ssr/lib/dist/react-ssr.esm.js:1696:1)

Possible Fix

🤷‍♂ I can't find any reference to document in the codebase so I don't know what's going on.

@ifiokjr
Copy link
Member

ifiokjr commented Jul 19, 2019

@hennessyevan I'll look into this. You don't by any chance have a sandbox I could look at?

@hennessyevan
Copy link
Collaborator Author

It's coming from this line in emotion which is strange but I think it's this issue emotion-js/emotion#1246, not anything about remirror. I'll keep this open until I figure it out and then post my findings here

image

@hennessyevan
Copy link
Collaborator Author

I don’t know much about rollup but is this a similar setting to webpack’s target? https://github.com/ifiokjr/remirror/blob/master/support/rollup/factory.js#L32

The emotion issue’s solution seems to be bundling with the ‘node’ target so that ‘isBrowser’ becomes false in ‘esm’.

I’ll check against my fork

@hennessyevan
Copy link
Collaborator Author

Yeah so I forked it and changed the browser setting but to no avail. It seems the @emotion/cache package gets bundled by https://github.com/preconstruct/preconstruct/blob/5674b34ca7ed9e46c7db4526eed249441089b0d3/src/build/rollup.js#L212 and document the isBrowser check gets swallowed up.

In the @remirror/react-ssr dist files this check is missing, I assume because of some check that preconstruct does at bundle time? I don't know enough about rollup though to figure out how to get the emotion cache code to behave in a browserless env. https://www.unpkg.com/@remirror/react-ssr@0.3.0/lib/dist/react-ssr.esm.js

@ifiokjr
Copy link
Member

ifiokjr commented Jul 20, 2019

@hennessyevan I'm looking at this now and have replicated your error.

ReferenceError: document is not defined
    at createCache

I've created a with-razzle project in the projects folder and will keep it around to run tests against going forward.

No guarantees, but I'll see if I can find a solution before the next release at some point this weekend.

@ifiokjr
Copy link
Member

ifiokjr commented Jul 21, 2019

@hennessyevan I've managed to find a fix for this. It'll be available in the next release.

It's a sneaky one and would likely have caused a lot of issues down the line so I appreciate you raising it.

I've added a brief explanation to #115 in case your interested 👍

@hennessyevan
Copy link
Collaborator Author

Fantastic!

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

Successfully merging a pull request may close this issue.

2 participants