Preview tool: Playwright browser serves stale JS cache across preview_stop/start cycles

Resolved 💬 2 comments Opened Mar 13, 2026 by erkanokman Closed Apr 11, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

The Preview tool's built-in Playwright browser persistently serves stale/cached JavaScript bundles even after the Next.js dev server is fully stopped, .next directory is deleted, and the server is restarted from scratch.

The compiled JS files on disk are correct and updated, but the Preview browser continues to load old versions. The user's real browser (Chrome) shows the correct updated code at the same time — only the Preview tool's browser is affected.

What Should Happen?

When the dev server is stopped, .next is deleted, and the server is restarted fresh, the Preview browser should load the newly compiled JavaScript — not a cached version from a previous session.

Error Messages/Logs

No error messages shown. Silent failure — Preview browser fetches stale JS silently.

Evidence:
File on disk (correct):
  wc -c .next/dev/static/chunks/src_618205f8._.js → 102283 bytes
  grep -c "adTr" → 10 matches

Preview browser fetch (stale):
  fetch('/_next/static/chunks/src_618205f8._.js').text().length → 77686 bytes
  (text.match(/adTr/g) || []).length → 0 matches

DOM confirms old code:
  labels: ["Nom (TR) *", "Description", "Couleur"]  ← OLD
  inputs: ["ad", "aciklama", "renk", "text"]          ← OLD

Chrome browser shows correct updated code simultaneously.

Steps to Reproduce

  1. Start dev server via preview_start (e.g., name: "flow-dev", port: 3444)
  2. Navigate to a page and verify it loads correctly
  3. Edit a source file (e.g., change a form layout significantly)
  4. Stop the preview: preview_stop
  5. Kill remaining process: lsof -ti :3444 | xargs kill -9
  6. Delete .next completely: rm -rf .next
  7. Verify deletion: ls .next → "No such file or directory"
  8. Start fresh: preview_start (returns reused: false)
  9. Navigate to the same page
  10. Observe: Browser still renders the OLD version of the component

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.63 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Root Cause Hypothesis:
The Playwright browser instance used by the Preview tool likely has an aggressive HTTP disk/memory cache that:

  1. Caches responses by URL (chunk filename hash doesn't change between Turbopack rebuilds)
  2. Does not respect Cache-Control headers from the dev server
  3. Persists across preview_stop / preview_start cycles (browser profile is not cleared)

What was tried (all failed):

  1. preview_stop → delete .nextpreview_start (reused: false)
  2. Kill process on port via kill -9 → delete .next → restart
  3. Delete node_modules/.cache and tsconfig.tsbuildinfo
  4. window.location.reload() via preview_eval
  5. window.location.replace('/path?_=' + Date.now()) (cache-busting URL)
  6. caches.keys().then(names => names.forEach(name => caches.delete(name))) via preview_eval
  7. Navigate to a completely different page and back

Suggested Fix:

  • Clear the Playwright browser's HTTP cache when preview_stop is called
  • Or: launch Playwright with --disable-http-cache flag
  • Or: use a fresh browser context/profile for each preview_start

Framework: Next.js 16.1.6 (App Router, Turbopack), port 3444
Frequency: 100% reproducible
Workaround: User's real browser (Chrome) works correctly; only Preview tool is affected

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗