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