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

[lexical-code][breaking change] Bug Fix: explicitly import instead of window. to support code nodes in nodejs #6562

Merged
merged 4 commits into from
Sep 7, 2024

Conversation

nadine-nguyen
Copy link
Contributor

@nadine-nguyen nadine-nguyen commented Aug 27, 2024

Description

Describe the changes in this pull request

Remove reference to window in CodeNode so the package can be used in node js. This is done by referencing Prism conditionally using global.Prism if it is in an environment where window is undefined

Closes #6563

Test plan

Before

Insert relevant screenshots/recordings/automated-tests

window is undefined error appears when creating a code node in a headless editor in a nodejs environment

After

Insert relevant screenshots/recordings/automated-tests

No error appears

Copy link

vercel bot commented Aug 27, 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 Aug 29, 2024 0:30am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 29, 2024 0:30am

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 27, 2024
Copy link

github-actions bot commented Aug 27, 2024

size-limit report 📦

Path Size
lexical - cjs 29.38 KB (0%)
lexical - esm 29.22 KB (0%)
@lexical/rich-text - cjs 37.87 KB (0%)
@lexical/rich-text - esm 31.08 KB (0%)
@lexical/plain-text - cjs 36.45 KB (0%)
@lexical/plain-text - esm 28.44 KB (0%)
@lexical/react - cjs 39.64 KB (0%)
@lexical/react - esm 32.52 KB (0%)

ivailop7
ivailop7 previously approved these changes Aug 27, 2024
@ivailop7
Copy link
Collaborator

ivailop7 commented Aug 27, 2024

There seems to be a build issue with Astro in the integration tests

scripts/tests/integration/fixtures/lexical-esm-astro-react › install & build succeeded

ChildProcessError: Command failed: npm run build
Named export 'languages' not found. The requested module 'prismjs' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'prismjs';

PrismJS is kind of abandoned and doesn't support ESM, we should probably move to Shiki at this point.

@ivailop7
Copy link
Collaborator

For this particular case, to unblock, since all the supported languages are listed in here: https://github.com/facebook/lexical/blob/main/packages/lexical-code/src/CodeHighlighterPrism.ts
You can export a const set with the listed languages here and check that particular set. Suboptimal, but should get things working.

@etrepum
Copy link
Collaborator

etrepum commented Aug 27, 2024

For what it's worth, last time I tried to make improvements to the way code highlighting imports prism it got undone by meta

@etrepum
Copy link
Collaborator

etrepum commented Aug 27, 2024

See also #5828

@nadine-nguyen
Copy link
Contributor Author

@etrepum Thanks for the link!
@ivailop7 I've decided to switch between window.Prism vs global.Prism, depending on whether window is defined. The integration check is now passing with this change. Let me know your thoughts

@nadine-nguyen nadine-nguyen requested a review from ivailop7 August 28, 2024 00:35
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

Looks good to me, but no idea if it will break Meta's build or not

@ivailop7
Copy link
Collaborator

@potatowagon could you check if this change would work for you internally?

@potatowagon potatowagon changed the title [lexical-code] Bug Fix: explicitly import instead of window. to support code nodes in nodejs [lexical-code][breaking change] Bug Fix: explicitly import instead of window. to support code nodes in nodejs Aug 28, 2024
@potatowagon
Copy link
Contributor

@potatowagon could you check if this change would work for you internally?

@potatowagon could you check if this change would work for you internally?

thanks for the headsup, labeled this as breaking change as a memo for further testing internally

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. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Unable to create CodeNodes in a nodejs headless environment
5 participants