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

Backport: Fix unstable_allowDynamic when used with pnpm #73765

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

unstubbable
Copy link
Contributor

Note

This is a backport of #73732 for Next.js 14.

When using dependencies in Middleware that make use of dynamic code evaluation, Next.js emits a build error because this is not supported in the Edge runtime.

In rare cases, when the code can not be reached at runtime and can't be removed by tree-shaking, users might opt in to using the unstable_allowDynamic config.

When combined with pnpm, the provided glob patterns as documented at https://nextjs.org/docs/messages/edge-dynamic-code-evaluation#possible-ways-to-fix-it did not match correctly because of pnpm's use of the .pnpm directory.

To fix the pattern matching, we need to provide the dot option to picomatch, which enables dotfile matching.

Side note: Ideally we would detect dynamic code evaluation after tree shaking, to reduce the number of cases where users need to revert to using unstable_allowDynamic.

fixes #51401

@ijjk ijjk added created-by: Next.js team PRs by the Next.js team. Documentation Related to Next.js' official documentation. tests type: next labels Dec 10, 2024
@unstubbable unstubbable force-pushed the hl/fix-unstable_allowDynamic-14 branch from 18595d7 to 4452834 Compare December 10, 2024 21:59
@ijjk
Copy link
Member

ijjk commented Dec 10, 2024

Tests Passed

@unstubbable unstubbable force-pushed the hl/fix-unstable_allowDynamic-14 branch from 4452834 to 030e73a Compare December 11, 2024 10:19
@unstubbable unstubbable changed the base branch from 14-2-1 to hl/fix-swc-react-14-2-1 December 11, 2024 10:19
Copy link
Contributor Author

unstubbable commented Dec 11, 2024

@ijjk
Copy link
Member

ijjk commented Dec 11, 2024

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
buildDuration 16s 13.8s N/A
buildDurationCached 7.7s 6.5s N/A
nodeModulesSize 201 MB 201 MB ⚠️ +540 B
nextStartRea..uration (ms) 406ms 413ms N/A
Client Bundles (main, webpack)
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
1a9f679d-HASH.js gzip 53.7 kB 53.7 kB N/A
5428.HASH.js gzip 181 B 180 B N/A
6067-HASH.js gzip 5.06 kB 5.06 kB N/A
6428-HASH.js gzip 31.6 kB 31.6 kB N/A
framework-HASH.js gzip 44.9 kB 44.9 kB
main-app-HASH.js gzip 241 B 241 B
main-HASH.js gzip 32.3 kB 32.3 kB N/A
webpack-HASH.js gzip 1.68 kB 1.68 kB N/A
Overall change 45.1 kB 45.1 kB
Legacy Client Bundles (polyfills)
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Overall change 39.4 kB 39.4 kB
Client Pages
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
_app-HASH.js gzip 196 B 196 B
_error-HASH.js gzip 184 B 185 B N/A
amp-HASH.js gzip 502 B 504 B N/A
css-HASH.js gzip 321 B 324 B N/A
dynamic-HASH.js gzip 1.82 kB 1.82 kB N/A
edge-ssr-HASH.js gzip 258 B 257 B N/A
head-HASH.js gzip 352 B 352 B
hooks-HASH.js gzip 371 B 372 B N/A
image-HASH.js gzip 4.23 kB 4.23 kB N/A
index-HASH.js gzip 259 B 257 B N/A
link-HASH.js gzip 2.67 kB 2.68 kB N/A
routerDirect..HASH.js gzip 316 B 314 B N/A
script-HASH.js gzip 385 B 386 B N/A
withRouter-HASH.js gzip 311 B 310 B N/A
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 654 B 654 B
Client Build Manifests
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
_buildManifest.js gzip 483 B 481 B N/A
Overall change 0 B 0 B
Rendered Page Sizes
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
index.html gzip 527 B 527 B
link.html gzip 540 B 539 B N/A
withRouter.html gzip 521 B 523 B N/A
Overall change 527 B 527 B
Edge SSR bundle Size
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
edge-ssr.js gzip 95.5 kB 95.5 kB N/A
page.js gzip 3.06 kB 3.06 kB N/A
Overall change 0 B 0 B
Middleware size
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
middleware-b..fest.js gzip 657 B 657 B
middleware-r..fest.js gzip 156 B 154 B N/A
middleware.js gzip 25.5 kB 25.5 kB
edge-runtime..pack.js gzip 839 B 839 B
Overall change 27 kB 27 kB
Next Runtimes
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
app-page-exp...dev.js gzip 171 kB 171 kB
app-page-exp..prod.js gzip 98.3 kB 98.3 kB
app-page-tur..prod.js gzip 100 kB 100 kB
app-page-tur..prod.js gzip 94.3 kB 94.3 kB
app-page.run...dev.js gzip 145 kB 145 kB
app-page.run..prod.js gzip 92.8 kB 92.8 kB
app-route-ex...dev.js gzip 22.5 kB 22.5 kB
app-route-ex..prod.js gzip 15.9 kB 15.9 kB
app-route-tu..prod.js gzip 15.9 kB 15.9 kB
app-route-tu..prod.js gzip 15.6 kB 15.6 kB
app-route.ru...dev.js gzip 22.2 kB 22.2 kB
app-route.ru..prod.js gzip 15.6 kB 15.6 kB
pages-api-tu..prod.js gzip 9.58 kB 9.58 kB
pages-api.ru...dev.js gzip 9.85 kB 9.85 kB
pages-api.ru..prod.js gzip 9.57 kB 9.57 kB
pages-turbo...prod.js gzip 22.5 kB 22.5 kB
pages.runtim...dev.js gzip 23.2 kB 23.2 kB
pages.runtim..prod.js gzip 22.5 kB 22.5 kB
server.runti..prod.js gzip 51.6 kB 51.6 kB
Overall change 959 kB 959 kB
build cache Overall increase ⚠️
vercel/next.js 14-2-1 vercel/next.js hl/fix-unstable_allowDynamic-14 Change
0.pack gzip 1.63 MB 1.63 MB ⚠️ +611 B
index.pack gzip 114 kB 114 kB ⚠️ +736 B
Overall change 1.74 MB 1.75 MB ⚠️ +1.35 kB
Diff details
Diff for middleware.js

Diff too large to display

Diff for edge-ssr.js

Diff too large to display

Commit: 0c6b9f9

Base automatically changed from hl/fix-swc-react-14-2-1 to 14-2-1 December 11, 2024 13:06
When using dependencies in Middleware that make use of dynamic code
evaluation, Next.js emits a build error because this is not supported in
the Edge runtime.

In rare cases, when the code can not be reached at runtime and can't be
removed by tree-shaking, users might opt in to using the
`unstable_allowDynamic` config.

When combined with pnpm, the provided glob patterns as documented at
https://nextjs.org/docs/messages/edge-dynamic-code-evaluation#possible-ways-to-fix-it
did not match correctly because of pnpm's use of the `.pnpm` directory.

To fix the pattern matching, we need to provide the `dot` option to
[picomatch](https://github.com/micromatch/picomatch), which enables
dotfile matching.

_Side note: Ideally we would detect dynamic code evaluation after tree
shaking, to reduce the number of cases where users need to revert to
using `unstable_allowDynamic`._

fixes #51401
@unstubbable unstubbable force-pushed the hl/fix-unstable_allowDynamic-14 branch from ef1d799 to 0c6b9f9 Compare December 11, 2024 13:10
@unstubbable unstubbable marked this pull request as ready for review December 11, 2024 14:36
@unstubbable unstubbable requested review from huozhi and ijjk December 11, 2024 14:36
@unstubbable unstubbable merged commit 049a690 into 14-2-1 Dec 12, 2024
52 of 57 checks passed
@unstubbable unstubbable deleted the hl/fix-unstable_allowDynamic-14 branch December 12, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
created-by: Next.js team PRs by the Next.js team. Documentation Related to Next.js' official documentation. tests type: next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants