-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
avoid top-level dynamic codemirror imports #2545
Conversation
🦋 Changeset detectedLatest commit: f1f8dda The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest changes of this PR are available as canary in npm (based on the declared
|
Codecov Report
@@ Coverage Diff @@
## main #2545 +/- ##
==========================================
+ Coverage 65.70% 69.45% +3.74%
==========================================
Files 85 71 -14
Lines 5106 4154 -952
Branches 1631 1375 -256
==========================================
- Hits 3355 2885 -470
+ Misses 1747 1264 -483
- Partials 4 5 +1
Continue to review full report at Codecov.
|
Why are they resolving unresolved promises though? The import should only happen on For example, the canonical react.lazy() examples declare unfulfilled dynamic imports this way |
// @ts-expect-error | ||
import('codemirror/keymap/sublime'), | ||
...addons, | ||
]; | ||
await Promise.all(allAddons.map(addon => addon)); |
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.
Not related to your PR, but why we need it? I guess it should be
await Promise.all(allAddons.map(addon => addon)); | |
await Promise.all(allAddons); |
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.
Yeah this was my original implementation! I wonder why map() was added? import() only resolves one value because its a promise, so I’m not sure what else it would be for
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.
In this place it makes no sens to do it 🙃
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.
Oops, now I forgot to include this 🙈 will follow up in another PR
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.
See #2559
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.
Hopefully this resolves the issue!
This has in fact nothing to do with bundlers after thinking about it again. In the moment you call As an example, you could do the following in Node.js:
What you'll see printed is first |
Indeed! I had a similar realization in the original issue comments. Thus why |
Fixes #2368
This should fix breaking imports of
@graphiql/react
(or its dependentgraphiql
) in non-browser environments like Node.js. Remix for example breaks during SSR because these imports also get loaded and executed.codemirror
assumes to always run in a browser env though.