-
Notifications
You must be signed in to change notification settings - Fork 2k
Use unnamed ESM imports for Prism modules #5828
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
5918193 to
74a79e2
Compare
74a79e2 to
fb70389
Compare
|
For what it's worth, other bundlers may tree-shake these out entirely since they're just imports that don't look like they have side-effects. Also setting I'd be happy to help sort this out, but I don't think there's a way for me to see what haste(?) does for the internal builds. |
4ecba41 to
20764cf
Compare
20764cf to
39448a2
Compare
e3b0b13 to
d0d61d3
Compare
@etrepum FWIW, thanks for taking a look into this, originally! Our internal build is actually handled within this repo, using the same Rollup config as the NPM build, minus a few differences using the It seems we were originally tree-shaking out the additional language modules for Prism in our Rollup config, but that's probably incorrect as we should include them internally I'm not sure how external third-party bundlers handle unnamed ESM imports for tree-shaking, but we've always bundled the Prism plugins this way for NPM, and I don't think we've not had any reports about languages being missing from Prism, so generally, I think we should be okay to retain them. |
|
|
||
| export const getCodeLanguages = (): Array<string> => | ||
| Object.keys(Prism.languages) | ||
| Object.keys(window.Prism.languages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we expect any impact to OSS consumers from changing this to global?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prism itself sets this as a window global which is how the languages register themselves on import, so I don't think so (unless they are calling it SSR without a window available somehow)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be okay on the server as well: https://github.com/PrismJS/prism/blob/master/prism.js#L1217-L1219
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly meant that getCodeLanguages() could throw on the server since there's not necessarily a window in scope here, if someone set global.window = global then it would be fine 🤷 Probably just a theoretical issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably just a theoretical issue.
I just faced it in nextjs with headless editor, global.window = global works fine though. (2wheeh/lexical-nextjs-ssr@5f1691d)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ I can confirm that this does the right thing in the environment I was able to reproduce the problem with before (an astro build). It also works correctly with next.js (when rebased on top of master to get the package.json fix), and the imports all seem to be present when manually inspecting the dev/prod output files.
|
Thanks @etrepum for confirming this still works on Astro and Next! Much appreciated. |
|
In remix, I am getting The side-effect import means it will run all the In my project, I now seeing Prism loaded on the During a production build, However, the other imports like |
I'm also facing the same issue with Next.js (14.2.3). I've tried to manually assign This only happens when building for production, though. It works as expected in dev. Edit: Fixed it. It turns out that I had to import |
This should fix a couple of bugs which are affecting our internal sync:
Prismis undefined" error when we try to build the internal apps with Haste - I'm not 100% sure why but there's an issue with bundling named ESM versions of CommonJS exports.Test plan
Ensure that additional Prism modules are still included in
LexicalCode.mjsandLexicalCode.prod.jsbuild by runningnpm run build.Ensure that additional Prism modules are now included in WWW build file
LexicalCode.prod.jsby runningnpm run build-www.Run an draft internal sync and ensure that everything is working correctly.