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

Next.js: Avoid conflicts with the raw loader #27093

Merged
merged 3 commits into from
May 14, 2024

Conversation

seanparmelee
Copy link
Contributor

Closes #26991

What I did

When @storybook/nextjs configures the SWC loader, it updates the raw loader rule to exclude __barrel_optimize__ requests, which pertain to Next's optimizePackageImports feature. For example, in a project using @mui/material, a resource may look like

__barrel_optimize__?names=Box,Button,Divider,Drawer,List,useMediaQuery,useTheme!=!./node_modules/.pnpm/@mui+material@5.15.15_@emotion+react@11.11.4_@types+react@18.3.1_react@18.3.1__@emotion+style_6tay2ra76drsmamcoqb5ygip6u/node_modules/@mui/material/index.js

and the Drawer here would match the /raw/ test, preventing the resource from being loaded correctly.

We could also just update the raw rule accordingly, but I figured since this is specific to Next.js and SWC, I put the logic in the configureSWCLoader function.

Checklist for Contributors

Testing

Looking for guidance on how you'd prefer this change be covered. I've tested this using a storybook that's using @storybook/nextjs and @mui/material with a story that uses the Drawer component. Would you prefer to have an integration test for this specific scenario?

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

There is a reproduction in #26991 (https://github.com/11bit/next-storybook-import-raw-bag) that could be used to confirm this story loads with these changes.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

@valentinpalkovic valentinpalkovic self-requested a review May 11, 2024 12:00
@valentinpalkovic valentinpalkovic self-assigned this May 11, 2024
@valentinpalkovic valentinpalkovic added bug nextjs ci:daily Run the CI jobs that normally run in the daily job. labels May 11, 2024
Copy link
Contributor

@valentinpalkovic valentinpalkovic left a comment

Choose a reason for hiding this comment

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

LGTM!

@seanparmelee Thank you for your contribution. It is much appreciated 🥳

@valentinpalkovic valentinpalkovic changed the title Next.js: avoid conflicts with the raw loader Next.js: Avoid conflicts with the raw loader May 14, 2024
Copy link

nx-cloud bot commented May 14, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 4993b00. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@valentinpalkovic valentinpalkovic merged commit f5fc402 into storybookjs:next May 14, 2024
99 of 102 checks passed
@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label May 14, 2024
storybook-bot pushed a commit that referenced this pull request May 14, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
storybook-bot pushed a commit that referenced this pull request May 14, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
storybook-bot pushed a commit that referenced this pull request May 14, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
storybook-bot pushed a commit that referenced this pull request May 14, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
@seanparmelee seanparmelee deleted the raw-conflicts branch May 14, 2024 15:28
storybook-bot pushed a commit that referenced this pull request May 14, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
storybook-bot pushed a commit that referenced this pull request May 14, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
storybook-bot pushed a commit that referenced this pull request May 15, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
storybook-bot pushed a commit that referenced this pull request May 15, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
storybook-bot pushed a commit that referenced this pull request May 15, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
@github-actions github-actions bot mentioned this pull request May 15, 2024
9 tasks
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label May 15, 2024
@valentinpalkovic
Copy link
Contributor

@seanparmelee it seems the PR has introduced a regression to everyone, who sets up a custom @svgr loader: #27195 (comment)

Can't we use the exclude property instead of test to exclude barrel requests?

@seanparmelee
Copy link
Contributor Author

seanparmelee commented May 19, 2024

Sorry about that @valentinpalkovic, yes exclude can be used instead. I can submit a PR with that change unless you're already planning to?

FWIW, we too are using @svgr/webpack, but we are mutating every rule that has .svg in test, similar to how you demonstrated in your comment.

@valentinpalkovic
Copy link
Contributor

@seanparmelee That would be amazing!

larsrickert pushed a commit that referenced this pull request Jun 8, 2024
Next.js: Avoid conflicts with the raw loader

(cherry picked from commit f5fc402)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ci:daily Run the CI jobs that normally run in the daily job. nextjs patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
2 participants