Unverified Commit 031b8fb8 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: only replace edge dynamic calls in dev (#84354)

This replacement should only happen in dev, it's really only to be able to have nicer error messages.

This previously failed the deployment tests.

Related: https://github.com/vercel/next.js/issues/40625

Closes PACK-5591
parent d300ee99
...@@ -174,14 +174,18 @@ pub async fn get_next_server_transforms_rules( ...@@ -174,14 +174,18 @@ pub async fn get_next_server_transforms_rules(
} }
if let NextRuntime::Edge = next_runtime { if let NextRuntime::Edge = next_runtime {
rules.push(get_middleware_dynamic_assert_rule(mdx_rs)); let mode = *mode.await?;
if mode == NextMode::Development {
rules.push(get_middleware_dynamic_assert_rule(mdx_rs));
}
if !foreign_code { if !foreign_code {
rules.push(next_edge_node_api_assert( rules.push(next_edge_node_api_assert(
mdx_rs, mdx_rs,
matches!(context_ty, ServerContextType::Middleware { .. }) matches!(context_ty, ServerContextType::Middleware { .. })
&& matches!(*mode.await?, NextMode::Build), && mode == NextMode::Build,
matches!(*mode.await?, NextMode::Build), mode == NextMode::Build,
)); ));
} }
......
...@@ -12,12 +12,13 @@ enum WrappedExpr { ...@@ -12,12 +12,13 @@ enum WrappedExpr {
WasmInstantiate, WasmInstantiate,
} }
/// Replaces call / expr to dynamic evaluation in the give code to /// Replaces call / expr to dynamic evaluation in the give code to wrapped expression
/// wrapped expression (__next_eval__, __next_webassembly_compile__,..) to raise /// (__next_eval__, __next_webassembly_compile__,..) to raise a (nicer) error message.
/// corresponding error.
/// ///
/// This transform is specific to edge runtime which are not allowed to /// This should only be only used in development mode.
/// call certain dynamic evaluation (eval, webassembly.instantiate, etc) ///
/// This transform is specific to edge runtime which are not allowed to call certain dynamic
/// evaluation (eval, webassembly.instantiate, etc)
/// ///
/// check middleware-plugin for corresponding webpack side transform. /// check middleware-plugin for corresponding webpack side transform.
pub fn next_middleware_dynamic() -> MiddlewareDynamic { pub fn next_middleware_dynamic() -> MiddlewareDynamic {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment