Skip to content

fix(rrweb): strip inlined worker sourceMappingURL comment (Angular build break in beta.6) - #197

Merged
krassx merged 3 commits into
mainfrom
fix/rrweb-worker-sourcemap-comment
Nov 12, 2026
Merged

krassx merged 3 commits into
mainfrom
fix/rrweb-worker-sourcemap-comment

Conversation

@krassx

@krassx krassx commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

@bugsee/rrweb@0.1.0-beta.6 breaks Angular's esbuild application builder (Unterminated string literal ... dist/index.js:9100). Angular strips ^//# sourceMappingURL=[^\r\n]* (gm) from dependency JS. rrweb's inlined image-bitmap worker is a template literal whose text ends \n//# sourceMappingURL=image-bitmap-data-url-worker-NVDCVKXO.js.map followed by the closing backtick on the same line (originates in the vendored record.js); the regex deleted the backtick and ;.

Fix

  • packages/rrweb/build/strip-inline-sourcemap.ts (build tooling, outside src/): esbuild onLoad plugin removing a line-start sourceMappingURL comment followed by a backtick on the same line. Wired into tsup.config.ts with expected: 1: the build fails if a vendor bump changes the number of such comments. The vendored record.js and its sha256 pin are untouched.
  • tsup writes the trailing //# sourceMappingURL=index.js.map twice; an onSuccess step (honouring the configured out dir) keeps one.
  • esbuild added as an rrweb devDependency.

Guard

  • scripts/check-dist-sourcemaps.mjs (pnpm check:dist-sourcemaps): for every packages/*/dist/**/*.{js,cjs,mjs}, a column-0 sourceMappingURL comment may only be in the trailing comment run, and the file must still parse after Angular's exact regex. Green over all 175 dist files.
  • Wired into ci.yml (builds rrweb, then scans) AND release.yml (after turbo run build, before publish, so every published dist is scanned).
  • packages/rrweb/build/dist-sourcemap-guard.test.ts builds the real package into a temp dir (so it cannot race turbo's own build on dist/), asserts the same, and extracts the inlined worker to syntax-check it and run a vm smoke.
  • Mutator check: removing the plugin fails the test and the script.
  • Not added: an Angular application-builder smoke (full Angular install per run); the guard emulates the failing step. A reviewer verified with real ng build on Angular 18/19/21: all fail on beta.6 and build with this change.

Note: the E2E job getting stuck on "Install Playwright's browsers" is runner infrastructure (same on other PRs); rerun it if it times out.

Version not bumped; beta.7 to be cut by the maintainer.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WeiJxSMPCqs6TBDKuGw9TG

…ild time (Angular break in beta.6)

Angular's esbuild builder deletes column-0 sourceMappingURL lines from dependencies; the inlined
worker template literal ended with one followed by the closing backtick, so dist/index.js stopped
parsing. Remove it at build time, dedupe the trailing comment, and add a dist guard (script + CI +
test) that emulates Angular's stripping over every package dist.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WeiJxSMPCqs6TBDKuGw9TG
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility with Angular builds by ensuring source-map comments in published JavaScript do not interfere with parsing.
    • Removed duplicate trailing source-map comments from package builds.
  • Reliability

    • Added checks during continuous integration and releases to catch source-map issues before packages are published.

The rrweb build now removes a specific inline source-map comment shape and deduplicates identical trailing source-map comments. A new script scans package distributions and checks parsing after applying Angular’s source-map stripping regex. Tests cover the transformation, duplicate-comment handling, and built rrweb outputs. CI and release workflows run the distribution check.

Sequence Diagram(s)

sequenceDiagram
  participant ciCheckJob
  participant rrwebBuild
  participant checkDistSourcemaps
  participant packageDistFiles
  participant checkSource
  participant esbuildParser
  ciCheckJob->>rrwebBuild: Build @bugsee/rrweb
  ciCheckJob->>checkDistSourcemaps: Run check:dist-sourcemaps
  checkDistSourcemaps->>packageDistFiles: Find JavaScript distribution files
  checkDistSourcemaps->>checkSource: Check code after Angular-style stripping
  checkSource->>esbuildParser: Parse stripped code
Loading

Possibly related PRs

Change: Bug fix

Merge Risk: Minimal · up to 9a8b0

This change fixes the Angular build break caused by stripping an inline source-map comment in the rrweb worker string. It adds checks that catch the failure shape before release. No merge-blocking risk remains in the supplied evidence.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly identifies the rrweb fix, the stripped inline worker source-map comment, and the Angular build failure it addresses.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description directly explains the Angular build failure, the source-map stripping fix, the new guard, and the related CI and release workflow changes.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 6 files. (5 skipped: 5 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2203277e-fd5c-423f-9790-a4d31fec5bb5
Commits

Reviewing files that changed from the base of the PR and between 554797d and 9a8b06b.

Files ignored due to path filters: 1

  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 11

  • .github/workflows/ci.yml
  • .github/workflows/release.yml
  • docs/PROGRESS.md
  • package.json
  • packages/rrweb/package.json
  • packages/rrweb/src/dist-sourcemap-guard.test.ts
  • packages/rrweb/src/strip-inline-sourcemap.test.ts
  • packages/rrweb/src/strip-inline-sourcemap.ts
  • packages/rrweb/tsup.config.ts
  • scripts/check-dist-sourcemaps.d.mts
  • scripts/check-dist-sourcemaps.mjs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@claude

claude Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Claude finished @krassx's task in 54s —— View job


Review of PR #197: strip inlined worker sourceMappingURL comment

I read the full diff against origin/main. I also checked the surrounding code: the vendored record.js, tsup.config.base.ts, ci.yml and release.yml. I did not run the build or the tests myself. I did run the plugin's regex over vendor/rrweb-record/record.js.

Findings (1 inline comment posted)

  • P3, .github/workflows/ci.yml:85: the guard doesn't cover what gets published. CI builds only @bugsee/rrweb before scanning, so only that package's dist/ is checked. release.yml builds everything (turbo run build) and publishes without running the guard. Suggested fix: add the pnpm check:dist-sourcemaps step after Build in release.yml. I can't edit workflow files.

Checked and found OK

  • The regex \r?\n?//[#@] sourceMappingURL=[^\r\n]*(?=) matches exactly one place in the vendored record.js: the \n//# sourceMappingURL=image-bitmap-data-url-worker-NVDCVKXO.js.map tail at offset 185992. The only other /*# sourceMappingURL= text is postcss's /*# form, which doesn't match. The vendored file and its sha pin stay untouched.
  • Removing the leading \n before the comment is safe, because the worker string just ends one line earlier.
  • dedupeTrailingSourceMap only collapses an identical duplicate at the end of the file. Distinct trailing comments are left alone, and the tests cover that.
  • The guard's ANGULAR_STRIP is identical to Angular's regex. The trailing-run logic correctly allows tsup's doubled tail while flagging any mid-file comment.
  • The onSuccess relative paths (dist/index.js, dist/index.cjs) assume the package directory as cwd. That holds for pnpm --filter … build, for turbo, and for the test's execFileSync(..., { cwd: pkgDir }).
  • strip-inline-sourcemap.ts imports node:fs/promises. It is reachable only from tsup.config.ts, not from src/index.ts or files: ["dist"], so it doesn't leak into shared runtime code.

Minor notes (no action required)

  • dist-sourcemap-guard.test.ts runs a full tsup build, including dts, in beforeAll with a 120 s timeout. Under coverage on a slow runner that could get close to the limit, so watch for flakiness. It also rewrites packages/rrweb/dist as a side effect, which is harmless because dev and the other tests consume src.
  • The guard emulates Angular's column-0 //# regex only. Other toolchains' source-map loaders use looser patterns, but that is out of scope for this fix.

Summary

  1. Overall risk: Low.
  2. Merge recommendation: Approve. The fix is narrowly scoped, the vendored file is untouched, and the tests cover both the plugin and the real built output.
  3. Most important thing to fix: wire check:dist-sourcemaps into release.yml after the build (P3, described above).
  4. Positives:
    • Fixing it at build time keeps the vendored record.js and its sha256 pin untouched.
    • The guard targets the whole class of bug, not just this one instance.
    • Both the plugin and the dedupe have mutation-style tests that assert exact output.
    • The CI step is cheap.

Comment thread .github/workflows/ci.yml Resolved
@claude

claude Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Claude finished @krassx's task in 14s —— View job


Re-review of PR #197 after the push (commit 9a8b06bf)

New findings: none.

Earlier finding: fixed. My P3 from the previous round said release.yml published without running the source-map guard. 9a8b06bf adds pnpm check:dist-sourcemaps right after turbo run build in .github/workflows/release.yml:64-67, before the publish step. That scans every freshly built dist/ just before publish, which was the suggested fix. The ci.yml step still builds only @bugsee/rrweb. That is acceptable now that the release path covers all packages.

Re-checked in this round

  • The script resolves esbuild through packages/rrweb/package.json. The release job does a full pnpm install, so the devDependency is available there too.
  • The ANGULAR_STRIP regex, the trailing-run logic in midFileComments, and the parse-after-strip check behave the same as before. The commit adds nothing else to the script.
  • dedupeTrailingSourceMap only collapses an identical duplicate at the very end of the file. Distinct trailing comments are left alone.
  • stripInlineSourceMapPlugin only returns new contents when the text actually changed. Every other module goes through esbuild's default loader.

I did not run the build, the tests, or the guard script in this run. This review is from reading the code.

Summary

  1. Overall risk: Low.
  2. Merge recommendation: Approve. The fix is narrowly scoped, and the vendored record.js and its sha256 pin are untouched. A guard now runs in both CI and release.
  3. Issues to fix: none outstanding.
  4. Positives:
    • The fix is at build time, so the vendored file stays pristine.
    • The guard checks for the whole class of bug, not just this instance.
    • The guard now runs on the exact artifacts that get published.
    • The plugin and the dedupe have tests that assert exact output.

Minor note from the previous round, still no action needed: dist-sourcemap-guard.test.ts runs a full tsup build with a 120 s timeout, so keep an eye on it for flakiness on slow runners.
· branch fix/rrweb-worker-sourcemap-comment

…strip, move build tooling out of src

- the guard test no longer cleans dist/ (raced turbo's concurrent build: ENOENT in onSuccess); the
  dedupe step honours the configured out dir
- the strip regex is anchored to line start and the build fails unless exactly one comment is stripped
- the built-package test extracts the inlined worker, syntax-checks it and runs a vm smoke
- tooling moved to packages/rrweb/build (coverage + tsconfig include it); temp dirs cleaned up

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WeiJxSMPCqs6TBDKuGw9TG
@claude

claude Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Claude finished @krassx's task in 54s —— View job


Re-review of PR #197 after the push (commit 622e830f)

New findings: none. I have no inline comments to post this round.

I reviewed 9a8b06bf..622e830f by reading the code. I did not install dependencies, so I did not run the build, the tests, the coverage gate or the guard script. CI on this commit (run 43048204772) was still in progress when I finished, so its result is the real check on the points below.

Earlier findings: the only one, the P3 about release.yml not running the guard, was fixed in 9a8b06bf.

What this push changes, and what I checked

  • Tooling moved out of src/. packages/rrweb/build/strip-inline-sourcemap.ts imports node:fs/promises. Only tsup.config.ts and the tests import it, and files: ["dist"] ships nothing from build/. So it can't leak into the runtime entry.
  • Line anchor. The regex is now (?:^|\r?\n)\/\/[#@] sourceMappingURL=[^\r\n]*(?=). It has no m flag, so ^ only matches at the start of the file, and the \r?\n alternative covers every other line start. That matches Angular's ^… with the gm flags. The tests cover the file start, CRLF, //@, a backtick on the next line, and a mid-line string.
  • Expected-count check.
    • found is declared inside setup() and reset in onStart, so the ESM and CJS builds count separately.
    • esbuild turns an onEnd throw into a build error, and the tests assert that both a lower and a higher count fail.
    • A vendor bump that adds or removes an inlined comment now fails the build instead of passing silently.
  • Guard test uses a temp dir. BUGSEE_RRWEB_OUT_DIR and --out-dir point at the same temp directory, so the test no longer cleans the real dist/ while turbo is building. onSuccess reads the same variable, so the dedupe step follows the override.
  • Worker smoke test. The fake OffscreenCanvas methods (getContext, drawImage, convertToBlob, close) are all called by the vendored worker, which I confirmed at vendor/rrweb-record/record.js:83-97. This makes it likely that including build/**/*.ts in the coverage include won't leave uncovered functions in the test file.

Things for CI to confirm (not blocking)

  • tsconfig rootDir. It changed from src to .. tsc --noEmit should be unaffected, and tsup's dts bundling names its output after the entry. The Lint · Typecheck · Cycles · Coverage job and check:publishable are where a changed dist/index.d.ts location would show up.
  • Test files in coverage. coverage.exclude still lists only src/**/*.test.ts, so build/**/*.test.ts counts toward the 100% line/function gate. The reasoning above suggests that's fine. If the coverage job reports an uncovered function in a test file, adding build/**/*.test.ts to exclude is the fix.
  • Guard-test timeout. The test runs a full tsup build with dts under a 120 s timeout, and the repo notes say coverage instrumentation can run 7–18x slower on CI. That is the likeliest flake.

Summary

  1. Overall risk: Low.
  2. Merge recommendation: Approve once CI is green.
  3. Issues to fix: none outstanding. I'd only act if CI flags one of the points above.
  4. Positives:
    • The temp-dir build removes a race with turbo.
    • The expected: 1 check turns a silent vendor-bump regression into a build failure.
    • The line-start anchor now matches the consumer's regex.
    • The guard runs in both CI and release.
      · branch fix/rrweb-worker-sourcemap-comment

@krassx
krassx merged commit ae67a28 into main Nov 12, 2026
@krassx
krassx deleted the fix/rrweb-worker-sourcemap-comment branch November 12, 2026 08:19
krassx added a commit that referenced this pull request Nov 19, 2026
Ships the @bugsee/rrweb fix for the Angular esbuild build break (#197) and everything merged since beta.6.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

1 participant