cloudflare/vinext

Pages Router: `next/head` manager re-executes inline scripts on re-render

クローズ

#1,473 opened on 2026/05/22

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)TypeScript (384 件のフォーク)github user discovery
adapter-api-e2ehelp wanted

Repository metrics

Stars
 (8,625 個のスター)
PR merge metrics
 (平均マージ 1d 1h) (30d で 462 merged PRs)

説明

This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext main vs Next.js v16.2.6, 2026-05-22).

Problem

When the Pages Router head manager updates <Script> tags during component re-renders, Next.js dedupes by src and does not re-execute already-loaded scripts. vinext re-executes them, causing the test's side-effect array to grow beyond ["src-1.js"]. The same issue applies whether or not a CSP nonce is set.

After re-render, scripts re-executed: side-effect array exceeds expected length

Estimated Impact

~2 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/nonce-head-manager/index.test.ts (2 failures)

Recommendation

  1. Reproduce first in vinext's own test suite. Add a Pages Router page that toggles state and re-renders a <Script src="./once.js">. Assert the script executes exactly once.

  2. Track loaded <Script> sources in the head manager. Maintain a Set<src> of already-injected scripts and skip re-injection during head reconciliation.

  3. Cover the nonce variant. Same dedup must apply when scripts carry a CSP nonce.

コントリビューターガイド