You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReferenceError: document is not defined. Server Side rendering does not seem to work. #6
I am trying to use the Markup component while rendering server side with preact-render-to-string.
I get the following error: 'ReferenceError: document is not defined'
Could you suggest a work around?
Reacted by Jason Miller, Chris Best, Valentin Agachi and Thomas Ebert
Ah yeah that's a good point. This uses the browser's built-in DOM parser, which isn't available under node. Should be possible to detect node and require() in a simple parser lib though! Will need to update the code :)
Activity
developit commentedon Sep 16, 2016
Ah yeah that's a good point. This uses the browser's built-in DOM parser, which isn't available under node. Should be possible to detect node and require() in a simple parser lib though! Will need to update the code :)
Add parsing when using SSR. Fixes developit#6.
danielweck commentedon Mar 30, 2021
Preact WMR injects a NodeJS
DOMParserfor static SSR (aka "prerender"):https://github.com/preactjs/wmr/blob/7077053172e4ef347397cdde375c806ab8f32d8e/docs/public/prerender.js#L6-L12
(PR context: https://github.com/preactjs/wmr/pull/497/files )
This way, this never fails:
preact-markup/src/parse-markup.js
Lines 22 to 26 in 4788b8d
...and this
iframe-based fallback never gets called in thehtmlcase:preact-markup/src/parse-markup.js
Lines 60 to 69 in 4788b8d
Related PRs:
#24
#22
#40
#18