-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Can't use generateHtmlFromNodes correctly for SSR #3616
Copy link
Copy link
Closed
Labels
Description
When using generateHtmlFromNodes, I encountered an error:
To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.
which is fine as JSDOM is required, but this error doesn't mention which variables this function needs, so I dig into the code and found that we need to declare something like this first to make it work:
const { JSDOM } = jsdom;
const window = new JSDOM(`...`).window;
global.document = window.document;
// @ts-expect-error
global.window = window;
// Sometimes `global.navigator` also needs to be defined with `global.window `
// @ts-expect-error
global.DocumentFragment = function() { return JSDOM.fragment(``) }This function is checking for both document and window. This should only check for document and DocumentFragment only, as these are the only methods generateHtmlFromNodes using.
Lexical version: 0.7.4
Reactions are currently unavailable