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

Removing global document references #1482

Merged

Conversation

AlfieJones
Copy link
Contributor

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.

Copy link

changeset-bot bot commented May 22, 2024

🦋 Changeset detected

Latest commit: 6869ab4

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
Copy link
Contributor

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
Copy link
Contributor Author

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

@eoghanmurray
Copy link
Contributor

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
Copy link
Contributor

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

Update patch text with my best understanding
@eoghanmurray eoghanmurray merged commit f3cf092 into rrweb-io:master Jun 4, 2024
3 of 4 checks passed
jeffdnguyen pushed a commit to pendo-io/rrweb that referenced this pull request Jul 29, 2024
fix for options `recordCanvas: true`: 
* replace document.createElement with doc.createElement in rrweb-snapshot code
* Eoghan: add a regression test to prevent future accidental use of `document` instead of `doc`.  This test can be excised if a new feature can only be run in the browser and not in the jsdom environment
jeffdnguyen pushed a commit to pendo-io/rrweb that referenced this pull request Jul 29, 2024
fix for options `recordCanvas: true`: 
* replace document.createElement with doc.createElement in rrweb-snapshot code
* Eoghan: add a regression test to prevent future accidental use of `document` instead of `doc`.  This test can be excised if a new feature can only be run in the browser and not in the jsdom environment
billyvg pushed a commit to getsentry/rrweb that referenced this pull request Sep 17, 2024
fix for options `recordCanvas: true`:
* replace document.createElement with doc.createElement in rrweb-snapshot code
* Eoghan: add a regression test to prevent future accidental use of `document` instead of `doc`.  This test can be excised if a new feature can only be run in the browser and not in the jsdom environment
jxiwang pushed a commit to amplitude/rrweb that referenced this pull request Oct 17, 2024
fix for options `recordCanvas: true`: 
* replace document.createElement with doc.createElement in rrweb-snapshot code
* Eoghan: add a regression test to prevent future accidental use of `document` instead of `doc`.  This test can be excised if a new feature can only be run in the browser and not in the jsdom environment
jxiwang pushed a commit to amplitude/rrweb that referenced this pull request Oct 17, 2024
fix for options `recordCanvas: true`: 
* replace document.createElement with doc.createElement in rrweb-snapshot code
* Eoghan: add a regression test to prevent future accidental use of `document` instead of `doc`.  This test can be excised if a new feature can only be run in the browser and not in the jsdom environment
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