3.19.0 appears to break server-side rendering by relying on window
cr3ative opened this issue · 2 comments
Hi there,
I'm really sorry that I couldn't find a simple way to replicate this with demo code, but hopefully I can be descriptive.
We use a mixed Preact/React stack at the moment, and use preact-render-to-string
to dump out the DOM to provide server-side rendering.
When our packages automatically updated to include preact-compat
3.19.0, SSR broke, with the following stack trace:
ReferenceError: window is not defined
at evalmachine.<anonymous>:7654:360
at ./node_modules/preact-context/dist/context.min.js (evalmachine.<anonymous>:7654:22)
at Object../node_modules/preact-context/dist/context.min.js (evalmachine.<anonymous>:7654:118)
at __webpack_require__ (evalmachine.<anonymous>:20:30)
at Module../node_modules/preact-compat/dist/preact-compat.es.js (evalmachine.<anonymous>:6985:72)
at __webpack_require__ (evalmachine.<anonymous>:20:30)
at Module../app/node_modules/@buzzfeed/react-components/dist/module/lib/components/CdnImage/index.js (evalmachine.<anonymous>:119:63)
at __webpack_require__ (evalmachine.<anonymous>:20:30)
at Module../app/static/js/render_kit/components/ResultCard.js (evalmachine.<anonymous>:2639:133)
at __webpack_require__ (evalmachine.<anonymous>:20:30)
This rendering kit uses a React component (CdnImage) and preact-compat
fails when this line, in that component, is imported:
import React, { Component } from 'react';
Something in there is relying on window
and we've bisected it to 3.19.0
I hope that helps. I'm sorry again for being so vague.
Hi Paul - just wanted to apologize for the radio silence on this issue.
You're right that this was introduced in 3.19, since the error is coming from createContext
, which was the most recently merged PR (#529). It looks like the issue is actually a build configuration error in preact-context - I'll try to find a fix there.
This should be fixed!