Skip to content

Fix releaseCapture crash on web and add ViewShot component example#604

Merged
gre merged 5 commits intomasterfrom
fix/web-viewshot-component
Mar 18, 2026
Merged

Fix releaseCapture crash on web and add ViewShot component example#604
gre merged 5 commits intomasterfrom
fix/web-viewshot-component

Conversation

@gre
Copy link
Copy Markdown
Owner

@gre gre commented Mar 18, 2026

Summary

  • Fix: releaseCapture on web was throwing "Tmpfile is not implemented" which crashed the app when ViewShot.onCapture tried to release the previous capture URI on a second capture. Changed to a no-op since there are no tmp files on web.
  • Example: Add a ViewShotComponentScreen to example-web that tests the ViewShot component (as opposed to captureRef with a plain View ref). Covers both manual capture via ref.capture() and automatic capture via captureMode="mount".
  • E2E: 2 new Playwright tests for the ViewShot component screen.

Ref #564

Test plan

  • npm test — 43 unit tests pass (updated releaseCapture test)
  • 12 Playwright E2E tests pass (including 2 new ViewShot component tests)
  • Manual test: capturing twice in a row no longer crashes on web

🤖 Generated with Claude Code

gre and others added 2 commits March 18, 2026 18:36
Adds example-web screen testing the ViewShot component (as opposed to
captureRef with a plain View ref). Covers both manual capture via
ref.capture() and automatic capture via captureMode="mount".

This validates that the ViewShot component works on web, addressing
the "Element is not attached to a Document" report in #564.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
releaseCapture on web was throwing "Tmpfile is not implemented" which
crashed the app when ViewShot.onCapture tried to release the previous
capture URI. Changed to a no-op since there are no tmp files on web.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 18, 2026 17:39
@gre
Copy link
Copy Markdown
Owner Author

gre commented Mar 18, 2026

Playwright shall regen new screenshots that will need to be amended in another commit

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the web implementation of react-native-view-shot by making releaseCapture safe on web and expands the example-web app with a new “ViewShot Component” screen plus Playwright coverage for component-based captures.

Changes:

  • Change releaseCapture on web from throwing to a no-op, and update unit tests accordingly.
  • Add a new ViewShotComponentScreen to the web example and wire it into navigation/types.
  • Add Playwright E2E tests (and one reference snapshot) covering ViewShot component ref.capture() and captureMode="mount".

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/RNViewShot.web.ts Makes releaseCapture a no-op on web to avoid runtime errors.
src/tests/RNViewShot.web.test.ts Updates unit test to assert releaseCapture does not throw.
example-web/src/types.ts Adds the ViewShotComponent route type.
example-web/src/screens/ViewShotComponentScreen.tsx New example screen demonstrating component capture + mount auto-capture.
example-web/src/screens/HomeScreen.tsx Adds the new test case entry to the home list.
example-web/src/App.tsx Wires navigation to the new screen.
example-web/e2e/viewshot.spec.ts Adds E2E tests and a visual snapshot for the new screen.
example-web/e2e/snapshots/reference/...viewshot-component-manual...png Adds the new reference snapshot (currently only for darwin).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +248 to +257
// Visual snapshot
await expect(previewImage).toHaveScreenshot(
"viewshot-component-manual.png",
{
threshold: 0.2,
maxDiffPixels: 1000,
scale: "css",
animations: "disabled",
},
);
Comment thread example-web/e2e/viewshot.spec.ts Outdated
gre and others added 3 commits March 18, 2026 18:47
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gre gre merged commit ddd86c4 into master Mar 18, 2026
6 checks passed
@gre gre mentioned this pull request May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants