From 223f969017221a2c26d4adebfcb3b5085024c1dc Mon Sep 17 00:00:00 2001 From: Kyle Gach Date: Fri, 18 Nov 2022 13:12:03 -0700 Subject: [PATCH] Update `newNextLinkBehavior` logic to match Next's --- code/frameworks/nextjs/src/config/webpack.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/code/frameworks/nextjs/src/config/webpack.ts b/code/frameworks/nextjs/src/config/webpack.ts index 1bc86473fe56..799f95a73df0 100644 --- a/code/frameworks/nextjs/src/config/webpack.ts +++ b/code/frameworks/nextjs/src/config/webpack.ts @@ -34,7 +34,20 @@ const setupRuntimeConfig = (baseConfig: WebpackConfig, nextConfig: NextConfig): }), }; - if (semver.gte(version, '13.0.0') || nextConfig.experimental?.newNextLinkBehavior) { + /** + * In Next12.2, the `newNextLinkBehavior` option was introduced, defaulted to + * falsy in the Next app (`undefined` in the config itself), and `next/link` + * was engineered to opt *in* to it + * + * In Next13, the `newNextLinkBehavior` option now defaults to truthy (still + * `undefined` in the config), and `next/link` was engineered to opt *out* + * of it + */ + const newNextLinkBehavior = nextConfig.experimental?.newNextLinkBehavior; + if ( + (semver.gte(version, '13.0.0') && newNextLinkBehavior !== false) || + (semver.gte(version, '12.2.0') && newNextLinkBehavior) + ) { definePluginConfig['process.env.__NEXT_NEW_LINK_BEHAVIOR'] = true; }