Skip to content

Discard stale async results in the source map textarea handler - #37

Merged
rmuratov merged 1 commit into
mainfrom
fix-sourcemap-input-race
Jul 5, 2026
Merged

Discard stale async results in the source map textarea handler#37
rmuratov merged 1 commit into
mainfrom
fix-sourcemap-input-race

Conversation

@rmuratov

@rmuratov rmuratov commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Closes #25

What

handleSourceMapTextAreaChange is async: every input event kicks off SourceMap.create, and nothing guaranteed the results applied in order. A slow parse could resolve after the user had already typed something else and then:

  • a stale successful parse cleared the textarea (wiping the newer input) and added the map,
  • a stale failed parse showed the "not a source map" error over a newer successful result.

How

Each handler invocation takes a monotonically increasing id from a ref; after await SourceMap.create(...) the result is applied only if the invocation is still the latest. A superseded-but-parsed source map has its consumer destroyed so it does not leak (same lifecycle rule as #23).

Tests

New source map input race suite delays the first SourceMap.create call so a later input finishes first, covering both orderings:

  • stale success does not wipe newer input, the map is not added, and its consumer is destroyed,
  • stale failure does not override the error state after a newer map was accepted.

Both fail against the previous handler and pass with the fix. Full suite 31/31, coverage stays at 100%.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 5, 2026

Copy link
Copy Markdown

Deploying sourcemap-tools with  Cloudflare Pages  Cloudflare Pages

Latest commit: fdc5f40
Status: ✅  Deploy successful!
Preview URL: https://8087c552.sourcemap-tools.pages.dev
Branch Preview URL: https://fix-sourcemap-input-race.sourcemap-tools.pages.dev

View logs

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (88b68db) to head (fdc5f40).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #37   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          208       213    +5     
  Branches        52        53    +1     
=========================================
+ Hits           208       213    +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rmuratov
rmuratov merged commit 8606456 into main Jul 5, 2026
4 checks passed
@rmuratov
rmuratov deleted the fix-sourcemap-input-race branch July 5, 2026 16:58
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.

Race condition in source map textarea handler

1 participant