Commit 54c65882 authored by Luke Sandberg's avatar Luke Sandberg Committed by Luke Sandberg

review

parent ec1c363d
......@@ -1571,6 +1571,8 @@ export async function copy_vendor_react(task_) {
* Replaces the body of a named function declaration/expression.
* Finds `function <name>(` and uses brace counting to locate the
* full body, then replaces it with the provided code.
*
* This is brittle but does work for our current usecase
*/
function replaceFunctionBody(
/** @type {string} */ code,
......@@ -1782,6 +1784,7 @@ export async function copy_vendor_react(task_) {
// to eliminate all promise tracking overhead — the chunks are
// already loaded synchronously, so we just need to call
// __next_chunk_load__ for side effects and handle async modules.
// TODO: this should be upstreamed into react
code = replaceFunctionBody(
code,
'preloadModule',
......
......@@ -96,11 +96,14 @@ function loadChunkPath(
const error = new Error(
sourceIsModule
? `Failed to load chunk ${chunkPath} from module ${sourceId}`
: `Failed to load chunk ${chunkPath} from runtime for chunk ${sourceId}`,
: `Failed to load chunk ${chunkPath} ${sourceId ? `from runtime for chunk ${sourceId}` : ''}`,
{ cause }
)
error.name = 'ChunkLoadError'
loadedChunks.set(chunkPath, error)
// Don't cache runtime chunk loading errors
if (!sourceIsModule) {
loadedChunks.set(chunkPath, error)
}
throw error
}
}
......
......@@ -61,7 +61,7 @@ contextPrototype.x = externalRequire
// Chunk loading is synchronous in these runtimes, so loaders may return plain
// values or throw. The async keyword ensures dynamic import() always returns
// a Promise per spec without an extra microtask in the browser path.
async function asyncLoaderSync(
async function asyncLoader(
this: TurbopackBaseContext<Module>,
moduleId: ModuleId
): Promise<Exports> {
......@@ -70,4 +70,4 @@ async function asyncLoaderSync(
) => Exports | Promise<Exports>
return loader(esmImport.bind(this))
}
contextPrototype.A = asyncLoaderSync
contextPrototype.A = asyncLoader
......@@ -174,14 +174,14 @@ impl EcmascriptChunkPlaceable for ManifestLoaderModule {
code,
r#"
{TURBOPACK_EXPORT_VALUE}((parentImport) => {{
var serverChunks = {chunks_server_data:#};
for (var i = 0; i < serverChunks.length; i++) {{
{TURBOPACK_LOAD}(serverChunks[i]);
}}
var chunks = {TURBOPACK_REQUIRE}({item_id});
var chunks = {chunks_server_data:#};
for (var i = 0; i < chunks.length; i++) {{
{TURBOPACK_LOAD}(chunks[i]);
}}
chunks = {TURBOPACK_REQUIRE}({item_id});
for (i = 0; i < chunks.length; i++) {{
{TURBOPACK_LOAD}(chunks[i]);
}}
return parentImport({dynamic_id});
}});
"#,
......
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