Unverified Commit 415cd74b authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

fix(next-api): correct font manifest generation (#62916)

### What

I noticed the font manifest generated by Turbopack was always empty.
Debugging showed that the path to the client_root was always incorrect
when calculating `get_font_paths_from_root`. And also fixed an issue
where for certain paths, the (`/index`) manifest key should contain the
original path.

Closes PACK-2666
parent 57abed52
...@@ -822,6 +822,7 @@ impl AppEndpoint { ...@@ -822,6 +822,7 @@ impl AppEndpoint {
this.app_project.app_dir(), this.app_project.app_dir(),
&app_entry.original_name, &app_entry.original_name,
&app_entry.original_name, &app_entry.original_name,
&app_entry.original_name,
client_assets, client_assets,
true, true,
) )
......
...@@ -18,17 +18,20 @@ pub(crate) async fn create_font_manifest( ...@@ -18,17 +18,20 @@ pub(crate) async fn create_font_manifest(
dir: Vc<FileSystemPath>, dir: Vc<FileSystemPath>,
original_name: &str, original_name: &str,
manifest_path_prefix: &str, manifest_path_prefix: &str,
pathname: &str,
client_assets: Vc<OutputAssets>, client_assets: Vc<OutputAssets>,
app_dir: bool, app_dir: bool,
) -> Result<Vc<Box<dyn OutputAsset>>> { ) -> Result<Vc<Box<dyn OutputAsset>>> {
// `_next` gets added again later, so we "strip" it here via
// `get_font_paths_from_root`.
let client_root_value = client_root.join("_next".to_string()).await?;
let all_client_output_assets = all_assets_from_entries(client_assets).await?; let all_client_output_assets = all_assets_from_entries(client_assets).await?;
let font_paths = // `_next` gets added again later, so we "strip" it here via
get_font_paths_from_root(&client_root_value, &all_client_output_assets).await?; // `get_font_paths_from_root`.
let font_paths: Vec<String> =
get_font_paths_from_root(&*client_root.await?, &all_client_output_assets)
.await?
.iter()
.filter_map(|p| p.split("_next/").last().map(|f| f.to_string()))
.collect();
let path = if app_dir { let path = if app_dir {
node_root.join(format!( node_root.join(format!(
...@@ -60,9 +63,7 @@ pub(crate) async fn create_font_manifest( ...@@ -60,9 +63,7 @@ pub(crate) async fn create_font_manifest(
} }
} else { } else {
NextFontManifest { NextFontManifest {
pages: [(original_name.to_string(), font_paths)] pages: [(pathname.to_string(), font_paths)].into_iter().collect(),
.into_iter()
.collect(),
pages_using_size_adjust: using_size_adjust, pages_using_size_adjust: using_size_adjust,
..Default::default() ..Default::default()
} }
......
...@@ -1020,6 +1020,7 @@ impl PageEndpoint { ...@@ -1020,6 +1020,7 @@ impl PageEndpoint {
this.pages_project.pages_dir(), this.pages_project.pages_dir(),
&original_name, &original_name,
&get_asset_prefix_from_pathname(&pathname), &get_asset_prefix_from_pathname(&pathname),
&pathname,
client_assets, client_assets,
false, false,
) )
......
...@@ -40,13 +40,17 @@ describe('next/font/google basepath', () => { ...@@ -40,13 +40,17 @@ describe('next/font/google basepath', () => {
// Preload // Preload
expect($('link[as="font"]').length).toBe(1) expect($('link[as="font"]').length).toBe(1)
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual(
as: 'font', expect.objectContaining({
crossorigin: 'anonymous', as: 'font',
href: '/dashboard/_next/static/media/0812efcfaefec5ea-s.p.woff2', crossorigin: 'anonymous',
rel: 'preload', href: expect.stringMatching(
type: 'font/woff2', /\/dashboard\/_next\/static\/media\/.*.p.*.woff2/
'data-next-font': 'size-adjust', ),
}) rel: 'preload',
type: 'font/woff2',
'data-next-font': 'size-adjust',
})
)
}) })
}) })
...@@ -6307,8 +6307,8 @@ ...@@ -6307,8 +6307,8 @@
"runtimeError": false "runtimeError": false
}, },
"test/e2e/next-font/basepath.test.ts": { "test/e2e/next-font/basepath.test.ts": {
"passed": [], "passed": ["next/font/google basepath preload correct files"],
"failed": ["next/font/google basepath preload correct files"], "failed": [],
"pending": [], "pending": [],
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
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