rrweb-io / rrweb

record and replay the web
https://www.rrweb.io/
MIT License
15.9k stars 1.38k forks source link

Removing global document references #1482

Closed AlfieJones closed 1 month ago

AlfieJones commented 1 month ago

In the rrweb-snapshot package, there are a few references to a global document object instead of using the doc parameter. This pr moves them to the doc parameter inline with the rest of the package.

There's room for improving the typescript support to throw an error when accessing the document element but I wasn't able to figure out a clean way to achieve this.

changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: 6869ab4b989225fc86aa6e3d54d0be06d2047b2c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages | Name | Type | | -------------------- | ----- | | rrweb-snapshot | Patch | | rrweb | Patch | | rrdom | Patch | | rrdom-nodejs | Patch | | rrweb-player | Patch | | @rrweb/types | Patch | | @rrweb/web-extension | Patch | | rrvideo | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

eoghanmurray commented 1 month ago

Hi Alfie, thanks for your PR!

Can you explain if there was a situation where the use of the global document failed here, or is it just for completeness? If it can fail maybe I can help you create a test for the situation.

AlfieJones commented 1 month ago

I was running the rebuild outside of a dom environment using jsdom so any references to the global document would fail.

eoghanmurray commented 1 month ago

Thank you. I've added a cursory test to ensure we don't get a regression in the main code paths. The one you fixed though was related to canvas and I couldn't recreate a failure using the jsdom in the tests without more effort. Feel free to add to that test if you wish it to prevent regressions in that sense, but overall it's probably not necessary.
If you think it's worthwhile to share what you tried in terms of typescript enforcement, I'd be interested to see how that might work.

eoghanmurray commented 1 month ago

I also explored a test on the rebuild side, but don't think it's worth adding; https://gist.github.com/eoghanmurray/52d0730eb8d7a209e27f29de0ddde455