Skip to content

fix(web): stop TrimmingTool effect from clearing the selected video - #2651

Merged
richiemcilroy merged 4 commits into
CapSoftware:mainfrom
MinitJain:discovery/trimming-tool-effect-loop
Oct 19, 2026
Merged

richiemcilroy merged 4 commits into
CapSoftware:mainfrom
MinitJain:discovery/trimming-tool-effect-loop

Conversation

@MinitJain

@MinitJain MinitJain commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The TrimmingTool effect lists a per-render cleanupResources as a dependency, so it re-runs after every commit. Its cleanup clears videoSrc, so the selected video never loads and the UI stays on "Loading video...".

Root cause

cleanupResources (TrimmingTool.tsx:76) is a plain function, so it is a new reference on every render. The effect at 700-725 has deps [cleanupResources, processingState.outputUrl]. After each commit the previous effect's cleanup calls cleanupResources(), which sets fileState.videoSrc = null and writes new state objects. The effect body also calls setVideoState, which writes another new object. Both writes trigger a re-render, which creates a new cleanupResources, and the cycle repeats. Commit 10ae2a2 changed the deps from [] to this list.

Fix

The Safari detection and the window dragover/drop listeners now run in a mount-only effect that no longer calls cleanupResources. Blob URLs are still cleaned up: cleanupResources revokes the old video URL when a new file is chosen; a mount-only effect revokes the current video URL on unmount (read through a ref); and an effect keyed on processingState.outputUrl revokes each trimmed output URL when it is replaced or the component unmounts.

How to reproduce

  1. Open /tools/trim (reproduced on cap.so on 2026-10-16).
  2. Choose any small video file.
  3. The tool stays on "Loading video..." and the preview never appears. The component re-renders continuously, even before a file is selected.

The regression test apps/web/__tests__/unit/trimming-tool-effect.test.ts reproduces it: it fails on the current code.

Tests

Regression test: apps/web/__tests__/unit/trimming-tool-effect.test.ts. It fails without the fix and passes with it.

Checks run locally:

  • scope: pass
  • regression test passes: pass
  • regression test fails at base: pass
  • lint: pass
  • related tests: pass
  • typecheck: pass
  • build: not run

Note: the production build (next build) was not run locally, because it needs the app's environment and services. Only the tests, lint and typecheck above were run.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

The PR separates window-listener cleanup from blob URL cleanup so the selected video stays loaded.

  • The trimming tool keeps the selected video preview loaded.

Reviews (2) · Last reviewed commit: "test(web): unmount TrimmingTool root in ..." · Reviewed by Greptile

The mount effect listed the per-render cleanupResources function as a
dependency, so it re-ran after every commit. Each cleanup reset videoSrc
to null and wrote new state, which re-rendered and repeated the cycle, so
a selected file never loaded.

Register the Safari detection and window drag listeners once on mount.
Revoke superseded output URLs through an effect keyed on outputUrl, and
revoke the latest video URL on unmount through a ref.
@vercel

vercel Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@MinitJain is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

@MinitJain
MinitJain marked this pull request as ready for review October 16, 2026 16:31
Comment thread apps/web/__tests__/unit/trimming-tool-effect.test.ts
Cleans up the React root even when an assertion fails before the test's own unmount.
@MinitJain

Copy link
Copy Markdown
Contributor Author

@greptileai please re-review the PR

@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Oct 19, 2026 4:55pm UTC

@vercel
vercel Bot temporarily deployed to Preview – cap-status October 19, 2026 13:36 Inactive
@vercel
vercel Bot temporarily deployed to Preview – cap-status October 19, 2026 16:55 Inactive
@richiemcilroy
richiemcilroy merged commit b93736a into CapSoftware:main Oct 19, 2026
29 of 30 checks passed

This branch was previously deployed

1 inactive deployment
Preview – cap-status — b367cb4c Deployed Oct 19, 2026 by vercel[bot]
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