[react-server-dom-turbopack] Support experimental array format for chunks (#37095)

Turbopack has introduced a new format for chunks (experimental):

```typescript
type ChunkUrlOrMerged = ChunkUrl | [ChunkUrl, ChunkPath[], number[]]
```

This will allow us to dynamically choose to merge / unmerge chunks based
on already loaded chunks. See
https://github.com/vercel/next.js/pull/95261 for more context behind
these feature.

However, we noticed that this breaks `prepareDestinationWithChunks()` on
server-side renders. The prepared chunk script tags were a stringified
version of this array:

<img width="1758" height="474" alt="Screenshot 2026-07-22 at 9 37 06 am"
src="https://github.com/user-attachments/assets/fa273b44-5942-4037-b955-4338472242fe"
/>

Instead, we should prepare the merged chunk as these SSR-d pages would
not have any loaded chunks tracked in memory (that happens on the
client).

This PR brings back this optimisation and also would remove the
console-logged errors associated with them.


---------

Co-authored-by: Sebastian "Sebbie" Silbermann <[email protected]>
This commit is contained in:
Sam Poder
2026-07-22 23:56:50 +02:00
committed by GitHub
co-authored by Sebastian Sebbie Silbermann
parent 13b8719923
commit e4dc33d9eb
6 changed files with 34 additions and 12 deletions
+5 -1
View File
@@ -146,7 +146,11 @@ declare const __webpack_require__: ((id: string) => any) & {
u: string => string,
};
declare function __turbopack_load_by_url__(id: string): Promise<mixed>;
// A chunk id is a plain filename, or a merged chunk emitted as
// `[mergedChunkFilename, componentChunkFilenames, componentChunkSizes]`.
declare function __turbopack_load_by_url__(
id: string | [string, Array<string>, Array<number>],
): Promise<mixed>;
declare const __turbopack_require__: ((id: string) => any) & {
u: string => string,
};