diff --git a/packages/compiler-test-utils/oracle/README.md b/packages/compiler-test-utils/oracle/README.md index 988af9512d..9d9a3d0930 100644 --- a/packages/compiler-test-utils/oracle/README.md +++ b/packages/compiler-test-utils/oracle/README.md @@ -96,8 +96,12 @@ fixes touched; every lane locally): - the 34 valid greens pass, apart from #34 rows that passed alone and green-sol/20's two expected pin flips; **one exception**: in green-sol/17's run the pin `known-bugs-start-compiler-dev.test.ts` "transforms a client module with a server fn and a top-level call of a pre-bundled dependency" (a dev-server deadlock) passed once, - at a load of about 22, and failed again alone. That pin can flip under load (first seen in about 210 suite - runs); not investigated yet; + at a load of about 22, and failed again alone (first flip in about 210 suite runs). F-N: the order of the + test's requests decided it, not the compiler. Vite's dependency optimizer ends its first crawl of static + imports when no request is in flight 50 ms after it starts; the test's first request came after + `createServer()` had started the optimizer, and a loaded machine can delay it past those 50 ms, so the + transform was not in the crawl and did not deadlock. The test now requests the module before the server + listens (Vite starts the optimizer in `listen()`), so the transform is always in the crawl; - 18 reds: the 14 whose catching rows are in files F-L or F-M changed, red-astra/12 and red-fable-r2/13 (caught by the dangling-name check, which F-L changed), red-fable/20 and red-astra-r2/15 (each caught by one row). All 18 are caught, by the same rows as before, except red-fable-r2/18 (99 rows instead of 100: "'always' logs a diff --git a/packages/start-plugin-core/tests/integration/known-bugs-start-compiler-dev.test.ts b/packages/start-plugin-core/tests/integration/known-bugs-start-compiler-dev.test.ts index 96e990fe57..49e5d24c6a 100644 --- a/packages/start-plugin-core/tests/integration/known-bugs-start-compiler-dev.test.ts +++ b/packages/start-plugin-core/tests/integration/known-bugs-start-compiler-dev.test.ts @@ -71,11 +71,16 @@ describe('Vite dev server', () => { } /** - * Starts a Vite dev server (middleware mode, empty dependency cache) on a - * temporary project with Start's whole Vite plugin, Start's real runtime - * (`linkStartRuntime`), `src/fn.ts` = `code` and `files` (in `src`), and - * requests the client transform of `src/fn.ts`, as the first request of - * the server. Returns `'hang'` when the transform stops making progress + * Creates a Vite dev server (empty dependency cache) on a temporary project + * with Start's whole Vite plugin, Start's real runtime (`linkStartRuntime`), + * `src/fn.ts` = `code` and `files` (in `src`), requests the client + * transform of `src/fn.ts`, and starts the server (`listen()`) once Vite + * loads that module. The transform is then in flight when Vite's dependency + * optimizer starts, so it is part of the optimizer's first crawl of static + * imports (the optimizer's first run waits for it), whatever the timing. A + * request made after the server started joins that crawl only when it + * reaches Vite within 50 ms of the optimizer's start, which a loaded machine + * can miss. Returns `'hang'` when the transform stops making progress * before it finishes (`settledOrHung`); otherwise the code it served. */ async function transformClientModule( @@ -90,6 +95,10 @@ describe('Vite dev server', () => { lastActivity = performance.now() return null } + const fnFile = path.join(root, 'src/fn.ts') + let fnLoading!: () => void + // Vite calls the load hooks of a module once it tracks its request + const fnLoaded = new Promise((resolve) => (fnLoading = resolve)) try { for (const [file, content] of Object.entries({ ...startPluginFiles, @@ -110,20 +119,30 @@ describe('Vite dev server', () => { logLevel: 'silent', cacheDir: path.join(root, '.vite'), appType: 'custom', - server: { middlewareMode: true, hmr: false, ws: false, watch: null }, + // One address, as the harness's other servers (FINAL-PASS #56) + server: { host: '127.0.0.1', hmr: false, ws: false, watch: null }, plugins: [ { name: 'record-activity', enforce: 'pre', resolveId: active, - load: active, + load(id) { + if (id === fnFile) { + fnLoading() + } + return active() + }, transform: active, }, startPlugin(root, {}), ], }) + // A server that is not listening yet has not started its dependency + // optimizer (Vite starts it in `listen()`) const transformed = server.environments.client.transformRequest('/src/fn.ts') + await Promise.race([fnLoaded, transformed.catch(() => {})]) + await server.listen() if ((await settledOrHung(transformed, () => lastActivity)) === 'hang') { transformed.catch(() => {}) return 'hang' as const @@ -206,9 +225,10 @@ export const fn = createServerFn().handler(() => 'MARK_HANDLER')`, // Source: the pin of the `z.object()` row above, before #8758. // Impact: with an empty dependency cache, such a module (an `object()` // schema from `import { object } from 'zod'` next to a server fn) never - // finishes transforming when it is requested as the dev server starts - // (`server.warmup`, the first request of a middleware-mode server, or - // `transformRequest()`), and the page hangs. + // finishes transforming when its transform is part of Vite's first crawl of + // static imports: requested before the server listens, or within about + // 50 ms of the dependency optimizer's start (`server.warmup`, the first + // request of a middleware-mode server), and the page hangs. test.fails( 'transforms a client module with a server fn and a top-level call of a pre-bundled dependency', async () => {