Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Bundle canvas worker manually #144

Merged
merged 3 commits into from
Dec 20, 2023
Merged

feat: Bundle canvas worker manually #144

merged 3 commits into from
Dec 20, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Dec 19, 2023

While trying to get the ReplayCanvas integration to properly tree shake, I noticed that the current way this worker is built is not ideal, and maybe is not treeshakeable properly. We use a rollup plugin to convert the worker to a base64 string, which a) is more verbose than just having the worker be a plain string, and b) possibly is not tree shakeable.

This refactors the worker to work the same way as the compression worker in Sentry - we build it to a string and use that in rrweb. This is a bit more complicated, from a setup perspective, but gives us full control over the worker build.

@mydea mydea requested review from billyvg and c298lee December 19, 2023 12:20
@mydea mydea self-assigned this Dec 19, 2023
Copy link

github-actions bot commented Dec 19, 2023

size-limit report 📦

Path Size
rrweb - record only (gzipped) 16.57 KB (0%)
rrweb - record & getCanvasManager only (gzipped) 19.11 KB (-9.49% 🔽)
rrweb - record only (min) 56.53 KB (0%)
rrweb - record with treeshaking flags (gzipped) 15.35 KB (0%)

@mydea
Copy link
Member Author

mydea commented Dec 19, 2023

Tracking this upstream as well: rrweb-io#1376

},
);
} catch {
// Error when initializing canvas...
Copy link
Member

Choose a reason for hiding this comment

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

Should this bubble up to error handler?

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, I'll wrap this in callbackWrapper instead!

Comment on lines +7 to +8
const workerBlob = new Blob([workerString]);
return URL.createObjectURL(workerBlob);
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean we'll have potential CSP errors now?

Copy link
Member Author

Choose a reason for hiding this comment

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

we already had before! Previously this was just being rewritten to a string-based worker by rollup under the hood 😬

@mydea mydea merged commit 10c8e45 into sentry-v2 Dec 20, 2023
14 checks passed
@mydea mydea deleted the fn/canvas-worker branch December 20, 2023 09:52
mydea added a commit to getsentry/sentry-javascript that referenced this pull request Jan 10, 2024
This bump contains the following changes:

- fix(rrweb): Use unpatched requestAnimationFrame when possible
[#150](getsentry/rrweb#150)
- ref: Avoid async in canvas
[#143](getsentry/rrweb#143)
- feat: Bundle canvas worker manually
[#144](getsentry/rrweb#144)
- build: Build for ES2020
[#142](getsentry/rrweb#142)

Extracted out from
#9826

Closes #6946
billyvg pushed a commit that referenced this pull request Apr 26, 2024
While trying to get the ReplayCanvas integration to properly tree shake,
I noticed that the current way this worker is built is not ideal, and
maybe is not treeshakeable properly. We use a rollup plugin to convert
the worker to a base64 string, which a) is more verbose than just having
the worker be a plain string, and b) possibly is not tree shakeable.

This refactors the worker to work the same way as the compression worker
in Sentry - we build it to a string and use that in rrweb. This is a bit
more complicated, from a setup perspective, but gives us full control
over the worker build.
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