|
| 1 | +# Bundle vendor directory |
| 2 | + |
| 3 | +Files under `_nextdeploy/runtime/vendor/` are copied into each compiled |
| 4 | +worker bundle at build time, not at request time. The Cloudflare Workers |
| 5 | +runtime has no `npm`, no filesystem, and no dynamic resolver — anything |
| 6 | +the runtime imports must already be inside the bundle when it ships. |
| 7 | + |
| 8 | +## What lives here |
| 9 | + |
| 10 | +`react-server-dom-webpack/server.edge.mjs` |
| 11 | +: Vendored by `VendorRSC` in `shared/nextcompile/vendor.go`. Resolved |
| 12 | + from the Next standalone tree's `node_modules`, then byte-copied |
| 13 | + into the bundle. Imported lazily by `runtime_src/rsc.mjs` to encode |
| 14 | + React Flight streams for App Router pages. |
| 15 | + |
| 16 | +This directory is otherwise empty in the source tree. It only fills up |
| 17 | +inside the per-build output directory after `VendorRSC` runs. |
| 18 | + |
| 19 | +## Why vendoring at all |
| 20 | + |
| 21 | +React Server Components needs `react-server-dom-webpack` at the edge. |
| 22 | +Three options were considered: |
| 23 | + |
| 24 | +1. **`npm install` in the worker** — impossible, Workers has no npm. |
| 25 | +2. **Re-publish a forked package** — drift; users' React version must |
| 26 | + match exactly. |
| 27 | +3. **Copy the package the user already installed** — what we do. |
| 28 | + |
| 29 | +Option 3 keeps the user's React/Next versions authoritative. The |
| 30 | +package the build resolves is the package the runtime executes. |
| 31 | + |
| 32 | +## Lookup contract |
| 33 | + |
| 34 | +`VendorRSC` walks up from the standalone directory looking for |
| 35 | +`node_modules/react-server-dom-webpack`, capped at 5 levels (handles |
| 36 | +pnpm/workspace layouts). Build flavor preference: ESM production → ESM |
| 37 | +development → legacy CJS. |
| 38 | + |
| 39 | +Failure surfaces as `ErrRSCPackageNotFound`. The compiler only treats |
| 40 | +that as fatal when `manifest.Features.RSC == true` — pages-only apps |
| 41 | +skip vendoring silently. |
| 42 | + |
| 43 | +## When this directory is regenerated |
| 44 | + |
| 45 | +Every build. `ExtractRuntime` writes the embedded source files first; |
| 46 | +`VendorRSC` lays the package on top. Both are idempotent — running a |
| 47 | +second build into the same output directory overwrites in place. |
0 commit comments