fix(snapshot): support no-unsafe-eval CSP by evaluating snapshot files server-side#10646
Open
lazerg wants to merge 1 commit into
Open
fix(snapshot): support no-unsafe-eval CSP by evaluating snapshot files server-side#10646lazerg wants to merge 1 commit into
lazerg wants to merge 1 commit into
Conversation
6 tasks
ba0b491 to
494b3a0
Compare
Author
|
the two windows failures aren't from this PR, both |
hi-ogawa
requested changes
Jun 23, 2026
hi-ogawa
left a comment
Collaborator
There was a problem hiding this comment.
I think we can go all-in as breaking change like:
- require
readSnapshotFileData - surface
populateerror as hard error and say something like "invalid snapshot file, please manually fix or delete (path to snapshot file)"
new e2e should cover
- csp wihtout unsave eval
- new hard error populate behavior
hi-ogawa
reviewed
Jun 23, 2026
| resolveRawPath: (testPath: string, rawPath: string) => Promise<string> | ||
| saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void> | ||
| readSnapshotFile: (filepath: string) => Promise<string | null> | ||
| readSnapshotFileData?: (filepath: string) => Promise<Record<string, string> | null> |
Collaborator
There was a problem hiding this comment.
On 2nd thought, it may be fine this is optional for integrator but fill up the default implementation on environment side somehow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In browser mode, when the page is served with a
no-unsafe-evalCSP policy,getSnapshotDatasilently fails to parse.snapfiles becausenew Function()is blocked. The emptycatch {}discards the error, leaving snapshot data empty and producing confusing mismatch failures with no hint about the real cause.This PR introduces an optional
readSnapshotFileDatamethod onSnapshotEnvironmentthat returns already-evaluated snapshot data. When the environment provides it,SnapshotState.create()uses it instead ofreadSnapshotFile + new Function, so the browser tester runtime never has to eval. The browser'sVitestBrowserSnapshotEnvironmentimplements the method by delegating to the server via RPC, where the file is read and evaluated safely in Node.js context.Resolves #10615