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

Check global.window on DOM availability check #5547

Merged
merged 2 commits into from
Jan 25, 2024

Conversation

2wheeh
Copy link
Contributor

@2wheeh 2wheeh commented Jan 25, 2024

There are some use cases @lexical/headless and $generateHtmlFromNodes in the server side and nextjs is probably the most common framework to implement this.

I found some issue and discussions related to this:

I've met same situation as well, which is that @lexical/headless is not compatible with nextjs servserside even with jsdom (or happy-dom) since #3102 (v.0.6.0)

I don't know why but anyway in nextjs, typeof window is still undefined after assigning global.window.
So it fails type assertion fixed in #3102.

Can reproduce here:

So could we check typeof global.window with typeof window?

Copy link

vercel bot commented Jan 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 25, 2024 3:35pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 25, 2024 3:35pm

@2wheeh 2wheeh changed the title Check global.window and global.document instead on DOM availability check Check global.window on DOM availability check Jan 25, 2024
Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I remember we had issues with window in the past #1400 ; even if this works fine I believe this PR might not be complete (iframe support and other occurences, we introduced this window utility for this

export function getWindow(editor: LexicalEditor): Window {
const windowObj = editor._window;
if (windowObj === null) {
invariant(false, 'window object not found');
}
return windowObj;
}
). In any case, I'm happy to merge as-is and we can iterate on this later

@zurfyx zurfyx merged commit fecdea1 into facebook:main Jan 25, 2024
42 of 45 checks passed
@2wheeh 2wheeh deleted the headless-generate-html branch January 26, 2024 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants