Unverified Commit e6688470 authored by Jimmy Miller's avatar Jimmy Miller Committed by GitHub

Properly disable laziness on next/dynamic (#98828)

next/dynamic assumes a eager semantic for css gathering, we are making
sure that holds even when lazy dynamic imports are enabled
parent 058456fa
......@@ -35,6 +35,7 @@ use turbopack_core::{
module_graph::{ModuleGraph, ModuleGraphLayer},
output::{OutputAssetsReference, OutputAssetsWithReferenced},
};
use turbopack_ecmascript::async_chunk::module::AsyncLoaderModule;
use crate::module_graph::DynamicImportEntriesWithImporter;
......@@ -52,6 +53,8 @@ pub(crate) async fn collect_next_dynamic_chunks(
chunking_availability: NextDynamicChunkAvailability<'_>,
) -> Result<ResolvedVc<DynamicImportedChunks>> {
let chunking_availability = &chunking_availability;
let module_graph = module_graph.to_resolved().await?;
let chunking_context = chunking_context.to_resolved().await?;
let dynamic_import_chunks = dynamic_import_entries
.iter()
.map(async |(dynamic_entry, parent_client_reference)| {
......@@ -77,8 +80,13 @@ pub(crate) async fn collect_next_dynamic_chunks(
}
};
// The react-loadable manifest needs the final CSS and JavaScript files so
// next/dynamic can preload them during SSR. Do not use a lazy manifest loader here.
let async_loader =
chunking_context.async_loader_chunk_item(*module, module_graph, availability_info);
AsyncLoaderModule::new(*module, *chunking_context, availability_info)
.to_resolved()
.await?
.as_chunk_item(*module_graph, *chunking_context);
let async_chunk_group = async_loader.references().to_resolved().await?;
Ok((*dynamic_entry, (*dynamic_entry, async_chunk_group)))
......
'use client'
import dynamic from 'next/dynamic'
const Target = dynamic(() => import('./target'))
export default function Page() {
return <Target />
}
.next-dynamic-css-target {
color: green;
--next-dynamic-css-marker: next-dynamic-css-marker;
}
import './target.css'
export default function Target() {
return <p className="next-dynamic-css-target">next/dynamic CSS target</p>
}
......@@ -285,6 +285,18 @@ export const invalid = ;`
}
})
it('preloads CSS for an SSR-rendered next/dynamic component', async () => {
const $ = await next.render$('/next-dynamic-css')
const href = $('link[rel="stylesheet"][data-precedence="dynamic"]').attr(
'href'
)
expect(href).toBeDefined()
expect(
await next.fetch(href!).then((response) => response.text())
).toContain('next-dynamic-css-marker')
})
it('activates a pattern import without colliding with its target', async () => {
const browser = await next.browser('/pattern')
const getActivationKeys = async (): Promise<string[]> =>
......
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