Apply server actions transform to node_modules in route handlers#89316
Conversation
The server actions transform, which handles the `'use cache'` directive, was not being applied to `node_modules` when imported from route handlers. This caused `'use cache'` functions from dependencies to fail with errors like `"cacheLife() can only be called inside a 'use cache' function"``. The issue was that the `AppRoute` context used `internal_custom_rules` for its foreign code module options, which did not include the server actions transform. This is inconsistent with `AppRSC` (App Router pages), which correctly uses `foreign_next_server_rules` that includes the transform. The fix extends `foreign_next_server_rules` with `internal_custom_rules` and uses it for the foreign code context in `AppRoute`, matching the pattern used by `AppRSC`.
Tests Passed |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles: **435 kB** → **435 kB** ✓81 files with content-based hashes (individual files not comparable between builds) Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
|
| internal_custom_rules.extend(common_next_server_rules); | ||
|
|
||
| next_server_rules.extend(source_transform_rules); | ||
| foreign_next_server_rules.extend(internal_custom_rules.clone()); |
There was a problem hiding this comment.
Is that actually necessary? sounds odd to run the internal rules on all of node_modules?
There was a problem hiding this comment.
It's not necessary for this fix, but it matches what we're doing for the other types: Pages, PagesApi, AppSSR, and AppRSC.
There was a problem hiding this comment.
It's identical to foreign_next_server_rules.extend(common_next_server_rules) in this case, because internal_custom_rules is empty for AppRoute.
…89316) The server actions transform, which handles the `'use cache'` directive, was not being applied to `node_modules` when imported from route handlers. This caused `'use cache'` functions from dependencies to fail with errors like `"cacheLife() can only be called inside a 'use cache' function"``. The issue was that the `AppRoute` context used `internal_custom_rules` for its foreign code module options, which did not include the server actions transform. This is inconsistent with `AppRSC` (App Router pages), which correctly uses `foreign_next_server_rules` that includes the transform. The fix extends `foreign_next_server_rules` with `internal_custom_rules` and uses it for the foreign code context in `AppRoute`, matching the pattern used by `AppRSC`.
The server actions transform, which handles the
'use cache'directive, was not being applied tonode_moduleswhen imported from route handlers. This caused'use cache'functions from dependencies to fail with errors like `"cacheLife() can only be called inside a 'use cache' function"``.The issue was that the
AppRoutecontext usedinternal_custom_rulesfor its foreign code module options, which did not include the server actions transform. This is inconsistent withAppRSC(App Router pages), which correctly usesforeign_next_server_rulesthat includes the transform.The fix extends
foreign_next_server_ruleswithinternal_custom_rulesand uses it for the foreign code context inAppRoute, matching the pattern used byAppRSC.