Unverified Commit 2c2dd5fe authored by zoomdong's avatar zoomdong Committed by GitHub

TURBOPACK: alias resolve lost query param (#88891)

parent 0921733a
// @ts-expect-error -- ignore // @ts-expect-error -- ignore
import { v } from './test.mdx?test=hi' import { v } from '@/test.mdx?test=hi'
// @ts-expect-error -- ignore // @ts-expect-error -- ignore
import reversed from './data.txt?reverse' import reversed from './data.txt?reverse'
// @ts-expect-error -- ignore // @ts-expect-error -- ignore
......
const path = require('path')
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
turbopack: { turbopack: {
...@@ -19,6 +21,9 @@ const nextConfig = { ...@@ -19,6 +21,9 @@ const nextConfig = {
}, },
], ],
}, },
resolveAlias: {
'@/*': './app/*',
},
}, },
webpack(config) { webpack(config) {
config.module.rules.push({ config.module.rules.push({
...@@ -33,6 +38,10 @@ const nextConfig = { ...@@ -33,6 +38,10 @@ const nextConfig = {
resourceQuery: /\?upper/, resourceQuery: /\?upper/,
use: require.resolve('./upper-loader.js'), use: require.resolve('./upper-loader.js'),
}) })
config.resolve.alias = {
...config.resolve.alias,
'@': path.resolve(__dirname, 'app'),
}
return config return config
}, },
} }
......
...@@ -2969,21 +2969,27 @@ async fn resolve_import_map_result( ...@@ -2969,21 +2969,27 @@ async fn resolve_import_map_result(
Ok(match result { Ok(match result {
ImportMapResult::Result(result) => Some(ResolveResultOrCell::Cell(**result)), ImportMapResult::Result(result) => Some(ResolveResultOrCell::Cell(**result)),
ImportMapResult::Alias(request, alias_lookup_path) => { ImportMapResult::Alias(request, alias_lookup_path) => {
let request = **request; let request_vc: Vc<Request> = **request;
let lookup_path = match alias_lookup_path { // Only add query if the aliased request doesn't already have one
Some(path) => path.clone(), let request = if request_vc.query().await?.is_empty() && !query.is_empty() {
None => lookup_path, request_vc.with_query(query.clone())
} else {
request_vc
}; };
// We must avoid cycles during resolving let lookup_path = alias_lookup_path.clone().unwrap_or(lookup_path);
if request == original_request && lookup_path == original_lookup_path {
// Compare request patterns to avoid cycles (ignoring query differences)
let request_pattern = request.request_pattern();
let original_pattern = original_request.request_pattern();
if *request_pattern.await? == *original_pattern.await?
&& lookup_path == original_lookup_path
{
None None
} else { } else {
let result = resolve_internal(lookup_path, request, options);
Some(ResolveResultOrCell::Cell( Some(ResolveResultOrCell::Cell(
result.with_replaced_request_key_pattern( resolve_internal(lookup_path, request, options)
request.request_pattern(), .with_replaced_request_key_pattern(request_pattern, original_pattern),
original_request.request_pattern(),
),
)) ))
} }
} }
......
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