-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Changed import of react-syntax-highlighter from esm to cjs #9292
Conversation
Changed imports for react-syntax-highlighter from esm to cjs since storybook is compiled to commonJS
added type to import of ReactSyntaxHighligter, fixed import to cjs module instead of esm, imported ReactHighlighterProps directly instead of using React.ComponentProps
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/storybook/monorepo/fpk321pjw |
The existing definitions for declare module 'react-syntax-highlighter/dist/cjs/languages/prism/jsx';
...etc |
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.
@Rikpat Thanks for the fix!!! It looks like it caused some regressions, however. Can you please take a look at the 3 updated Chromatic snapshots and see if you can figure out what's going on? Thanks!
I tried adding JS and MD into the highligter but it still has the same problem I created a codesandbox to find out why does it do that. |
@Rikpat thanks for digging into this. The strange thing is that your PR has even more differences than my PR to the syntax highlighting. There is definitely something strange going on, perhaps there is a race condition somewhere? |
@LarsDenBakker I was trying to fix it by importing and registering jsExtras and cssExtras directly from refractor, it fixed js highlighting, but cssExtras do break css highlighting for some reason. It works in isolated environment, but it doesn't work in storybook. |
I'm wondering wether changing to https://github.com/rexxars/react-refractor would help. |
…t/9292 # Conflicts: # lib/components/package.json
If that's the case, then yeah, back to my original suggestion of just changing the esm -> cjs imports in this PR. Then I can look at the regressions introduced by those changes separately. |
@mAAdhaTTah Are you proposing I merge this and release on an alpha, and then you will follow up from there? (I'm fine with that plan, just want to confirm) |
@shilman I'm proposing the PR be updated so it's back to just changing esm -> cjs, if I understood this correctly:
Then the regression issue (which sounds like is caused by deep-importing that package) could be looked at separately. |
Yes it sounds like separating these 2 things out into 2 separate PRs is a good plan. Perhaps best is to leave this one, and open another with just the ESM => CJS change and if everything checks out release that into a 5.3.x patch |
@mAAdhaTTah gotcha. glad i checked. sometimes when you're handling 100+ notifications per day, the words just start running together... 🙈 |
No worries, it happens. I'll poke at #9287 to see what I can do about the deep imports regression. |
Not stale. |
@mAAdhaTTah you've seen #9780 and #9795 right? both went out in 6.0-alpha |
@shilman No, thanks for pointing that out. Unfortunately, I haven't had the time to look into this, but I'm not sure I'm going to in the near future, so if it's in 6.0, maybe that's fine. Sorry I couldn't be more helpful. |
@mAAdhaTTah no worries. just wanted to let you and anybody else on this PR know about that incremental change. pretty sure there's more to do here, but it's all a little over my head. |
# Conflicts: # addons/storysource/src/StoryPanel.js # lib/components/package.json # lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx # yarn.lock
# Conflicts: # lib/components/package.json
This turned into some cleanup & I added 2 new languages: yml & markdown |
Will this land on 5x or should I try to adopt 6x to have this sorted? Happy to jump to 6x if it's in a good state? Are there any migration docs? |
# Conflicts: # lib/components/package.json # yarn.lock
…9292 # Conflicts: # lib/components/package.json
@Dashue 6.x and there are migration instructions in MIGRATION.md. I usually write them up in a post as well before the release goes out. https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#from-version-53x-to-60x |
Issue: #9279
What I did
Changed imports from ESModules to CommonJS modules for react-syntax-highlighter.
I had to change import to require because CommonJS modules don't have typescript definitions and would fail tests.
I noticed PR #9287 and also included that change, but with CommonJS import and manual type definition. In case this PR gets merged, that PR becomes obsolete.
I had to import props for ReactSyntaxHighlighter so I removed the line that got them directly from the component and used the imported props instead.
How to test
Nothing really changed except for imports and typescript declaration, so I don't think any changes in testing or documentation are necessary
Closes #9279, overrides #9287, and also addresses #9282