diff --git a/code/frameworks/nextjs/src/config/webpack.ts b/code/frameworks/nextjs/src/config/webpack.ts index e2ee693723e..60c095219cd 100644 --- a/code/frameworks/nextjs/src/config/webpack.ts +++ b/code/frameworks/nextjs/src/config/webpack.ts @@ -34,26 +34,22 @@ const setupRuntimeConfig = (baseConfig: WebpackConfig, nextConfig: NextConfig): }), }; + const newNextLinkBehavior = nextConfig.experimental?.newNextLinkBehavior; + /** - * In Next 12.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 Next 13.0.0, the `newNextLinkBehavior` option now defaults to truthy (still + * In Next 13.0.0 - 13.0.6, the `newNextLinkBehavior` option now defaults to truthy (still * `undefined` in the config), and `next/link` was engineered to opt *out* * of it * - * In Next 13.0.6 the `next/link` updated the default newNextLinkBehavior condition check - * to be `true` if the `newNextLinkBehavior` is not `false` */ - const newNextLinkBehavior = nextConfig.experimental?.newNextLinkBehavior; if ( - (semver.gte(version, '13.0.0') && - semver.lt(version, '13.0.6') && - newNextLinkBehavior !== false) || - (semver.gte(version, '12.2.0') && newNextLinkBehavior) + semver.gte(version, '13.0.0') && + semver.lt(version, '13.0.6') && + newNextLinkBehavior !== false ) { definePluginConfig['process.env.__NEXT_NEW_LINK_BEHAVIOR'] = true; + } else { + definePluginConfig['process.env.__NEXT_NEW_LINK_BEHAVIOR'] = newNextLinkBehavior; } baseConfig.plugins?.push(new DefinePlugin(definePluginConfig));