Unverified Commit 206fa758 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: fix pageExtensions precedence (#84926)

Webpack doesn't use the specified order, it's by length.
parent 1bb64bf9
...@@ -1388,7 +1388,12 @@ impl NextConfig { ...@@ -1388,7 +1388,12 @@ impl NextConfig {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn page_extensions(&self) -> Vc<Vec<RcStr>> { pub fn page_extensions(&self) -> Vc<Vec<RcStr>> {
Vc::cell(self.page_extensions.clone()) // Sort page extensions by length descending. This mirrors the Webpack behavior in Next.js,
// which just builds a regex alternative, which greedily matches the longest
// extension: https://github.com/vercel/next.js/blob/32476071fe331948d89a35c391eb578aed8de979/packages/next/src/build/entries.ts#L409
let mut extensions = self.page_extensions.clone();
extensions.sort_by_key(|ext| std::cmp::Reverse(ext.len()));
Vc::cell(extensions)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
module.exports = { module.exports = (phase, { defaultConfig }) => ({
pageExtensions: ['page.js'], // Append the custom extension to the default page extensions, to ensure that matching precedence
} // is by length.
pageExtensions: [...defaultConfig.pageExtensions, 'page.js'],
})
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