Skip to content

Add snapshot test for parallel slot flight router state#91148

Draft
sokra wants to merge 1 commit intocanaryfrom
janka/slot-flight2
Draft

Add snapshot test for parallel slot flight router state#91148
sokra wants to merge 1 commit intocanaryfrom
janka/slot-flight2

Conversation

@sokra
Copy link
Copy Markdown
Member

@sokra sokra commented Mar 10, 2026

What?

Adds an e2e snapshot test that captures the flight router state tree produced for parallel routes using @slot.

Why?

There is a discrepancy between Turbopack and Webpack in how they represent parallel slot segments in the flight router state:

  • @slot/page.tsx (direct page): Turbopack produces "(slot)" as the segment, while Webpack produces "__PAGE__".
  • @slot/nested/page.tsx (nested page): Both bundlers agree on "(slot)".

Root cause:

  • Webpack (next-app-loader/index.ts): When @slot/page.tsx exists directly (line 752-757), it matches as [PAGE_SEGMENT] which gets normalized to __PAGE__. Only nested parallel routes trigger PARALLEL_VIRTUAL_SEGMENT(slot).
  • Turbopack (app_structure.rs): Unconditionally sets tree.segment = "(slot)" for any @parallel directory (line 1264-1268), regardless of nesting.

This test captures the current Turbopack behavior in inline snapshots so the discrepancy is visible and trackable.

How?

New test at test/e2e/app-dir/parallel-routes-flight-router-state/:

Fixture:

app/
  layout.tsx          # Root layout accepting children + slot
  page.tsx            # Main page
  nested/page.tsx     # Nested main page
  @slot/
    page.tsx          # Direct page in slot
    default.tsx       # Default fallback
    nested/page.tsx   # Nested page in slot

Tests:

  1. Fetches HTML for / and /nested
  2. Extracts the flight router state tree from the RSC payload (__next_f script tags)
  3. Inline snapshot asserts the tree structure

Current results:

  • Turbopack (dev + start): 2/2 pass
  • Webpack (start): 1/2 fail — the / route snapshot differs (__PAGE__ vs (slot))

Tests the flight router state tree for parallel routes with @slot,
capturing the discrepancy between turbopack and webpack:
- Turbopack uses "(slot)" segment for direct @slot/page.tsx
- Webpack uses "__PAGE__" segment for direct @slot/page.tsx
- Both agree on "(slot)" for nested @slot/nested/page.tsx
@nextjs-bot nextjs-bot added created-by: Turbopack team PRs by the Turbopack team. tests labels Mar 10, 2026
@nextjs-bot
Copy link
Copy Markdown
Collaborator

nextjs-bot commented Mar 10, 2026

Failing test suites

Commit: ae84042 | About building and testing Next.js

pnpm test-dev test/e2e/app-dir/parallel-routes-flight-router-state/parallel-routes-flight-router-state.test.ts (job)

  • parallel-routes-flight-router-state > should have correct flight router state for / (direct slot page) (DD)
  • parallel-routes-flight-router-state > should have correct flight router state for /nested (nested slot page) (DD)
Expand output

● parallel-routes-flight-router-state › should have correct flight router state for / (direct slot page)

Could not extract flight router state from HTML

  34 |       }
  35 |     }
> 36 |     throw new Error('Could not extract flight router state from HTML')
     |           ^
  37 |   }
  38 |
  39 |   it('should have correct flight router state for / (direct slot page)', async () => {

  at extractFlightRouterState (e2e/app-dir/parallel-routes-flight-router-state/parallel-routes-flight-router-state.test.ts:36:11)
  at Object.extractFlightRouterState (e2e/app-dir/parallel-routes-flight-router-state/parallel-routes-flight-router-state.test.ts:41:18)

● parallel-routes-flight-router-state › should have correct flight router state for /nested (nested slot page)

Could not extract flight router state from HTML

  34 |       }
  35 |     }
> 36 |     throw new Error('Could not extract flight router state from HTML')
     |           ^
  37 |   }
  38 |
  39 |   it('should have correct flight router state for / (direct slot page)', async () => {

  at extractFlightRouterState (e2e/app-dir/parallel-routes-flight-router-state/parallel-routes-flight-router-state.test.ts:36:11)
  at Object.extractFlightRouterState (e2e/app-dir/parallel-routes-flight-router-state/parallel-routes-flight-router-state.test.ts:69:18)

pnpm test test/integration/telemetry/test/index.test.ts (turbopack) (job)

  • Telemetry CLI > production mode > emits event when swc fails to load (DD)
Expand output

● Telemetry CLI › production mode › emits event when swc fails to load

expect(received).toMatch(expected)

Expected pattern: /NEXT_SWC_LOAD_FAILURE/
Received string:  "⚠ Failed to load triple linux-x64-gnu: Cannot load native addon because loading addons is disabled.
⚠ Failed to load triple linux-x64-musl: Cannot find module '/root/actions-runner/_work/next.js/next.js/packages/next-swc/native/next-swc.linux-x64-musl.node'
Require stack:
- /root/actions-runner/_work/next.js/next.js/packages/next/dist/build/swc/index.js
- /root/actions-runner/_work/next.js/next.js/packages/next/dist/build/analysis/parse-module.js
- /root/actions-runner/_work/next.js/next.js/packages/next/dist/build/analysis/get-page-static-info.js
- /root/actions-runner/_work/next.js/next.js/packages/next/dist/build/route-discovery.js
- /root/actions-runner/_work/next.js/next.js/packages/next/dist/build/index.js
- /root/actions-runner/_work/next.js/next.js/packages/next/dist/cli/next-build.js
⚠ Attempted to load @next/swc-wasm-nodejs, but it was not installed
⚠ Attempted to load @next/swc-wasm-web, but it was not installed
⨯ Failed to load SWC binary for linux/x64, see more info here: https://nextjs.org/docs/messages/failed-loading-swc·
> Build error occurred
Error: Failed to load SWC binary for linux/x64, see more info here: https://nextjs.org/docs/messages/failed-loading-swc

  at <unknown> (../dist/build/swc/index.js:323:38)
  "
  at Object.toMatch (integration/telemetry/test/index.test.ts:111:24)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

created-by: Turbopack team PRs by the Turbopack team. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants