Skip to content

fix(playground): keep multi-file output consistent after a failed compilation - #12632

Open
Ahsan Shiekh (ahsansheikh94) wants to merge 1 commit into
microsoft:mainfrom
ahsansheikh94:cursor/playground-output-snapshot-6427
Open

Ahsan Shiekh (ahsansheikh94) wants to merge 1 commit into
microsoft:mainfrom
ahsansheikh94:cursor/playground-output-snapshot-6427

Conversation

@ahsansheikh94

Copy link
Copy Markdown

Closes #12630

Follow-up to #12546. After a successful compile, the playground now reads every emitted file into a single snapshot while that compile still owns tsp-output. When a later compile fails and the previous file list is kept, every file is shown from that snapshot. Before this, only files you had opened were cached, so a file could show an older version or show nothing if you had never opened it.

  • New output-snapshot.ts helper, used by use-compilation.ts. file-viewer.tsx falls back to the snapshot instead of its own per-selection cache.
  • Multi-file snapshots are capped at 32MB of text so large outputs can't grow without bound. A single emitted file is always kept, so the existing single-file fallback works the same way.
  • Added tests for the snapshot logic and for the repro steps in the issue (file-viewer).

pnpm test in packages/playground passes (71 tests), and lint/prettier are clean.

…pilation

Snapshot every emitted file after a successful compile and reuse that
snapshot when a later compile fails and clears tsp-output.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two unresolved issues can mix filenames and content from different compilations: snapshot read failures preserve mismatched state, and the file viewer reads shared output instead of preferring retained snapshot text.

2 open issues
What changed in this PR

Extends the playground’s failed-compilation fallback to multi-file output, addressing #12630 and following up on #12546. Compilation-wide snapshots replace the viewer’s cache of previously opened files.

Changes:

  • Captures emitted text before another compilation clears the output, with bounded multi-file retention and a single-file exemption.
  • Passes snapshots through compilation state to the file viewer for fallback display.
  • Adds snapshot and viewer regression tests, plus a changelog entry.
File Description
packages/​playground/​test/​output-snapshot.test.ts Tests retention, read failures, and snapshot limits.
packages/​playground/​test/​file-viewer.test.tsx Tests fallback for changed and previously unopened files.
packages/​playground/​src/​react/​types.ts Adds optional snapshot contents to compilation and viewer types.
packages/​playground/​src/​react/​output-view/​output-view.tsx Forwards snapshot contents to output viewers.
packages/​playground/​src/​react/​output-view/​file-viewer.tsx Replaces the per-selection cache with snapshot fallback.
packages/​playground/​src/​react/​hooks/​use-compilation.ts Captures snapshots while compilation owns the output directory.
packages/​playground/​src/​react/​compilation/​output-snapshot.ts Implements snapshot reading, size limits, and retained-output selection.
.chronus/​changes/​playground-multi-file-output-snapshot.md Documents the playground fallback fix.

Review effort: Balanced

Comment on lines +105 to +111
const nextRetained: RetainedOutput =
state.outputFiles.length > 0
? {
outputFiles: [...state.outputFiles],
outputFileContents: snapshot ?? retained.outputFileContents,
}
: retained;
// Failed compilations keep the previous file list after tsp-output was emptied.
setContent(lastContentsRef.current.get(path) ?? "");
// The snapshot is every file from that compilation, not only files opened since.
setContent(outputFileContents?.get(path) ?? "");

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playground shows stale or blank multi-file output after a failed compilation

2 participants