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

rum-recorder: import rrweb-snapshot code #700

Merged
merged 8 commits into from
Feb 2, 2021
Merged

Conversation

vlad-mh
Copy link
Contributor

@vlad-mh vlad-mh commented Jan 22, 2021

This PR removes the dependency on rrweb-snapshot and instead adds it's code directly, changing the imports accordingly.

@codecov-io
Copy link

codecov-io commented Jan 22, 2021

Codecov Report

Merging #700 (418a14d) into master (8dea89b) will decrease coverage by 1.67%.
The diff coverage is 58.06%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #700      +/-   ##
==========================================
- Coverage   79.84%   78.17%   -1.68%     
==========================================
  Files          69       71       +2     
  Lines        3433     3743     +310     
  Branches      732      887     +155     
==========================================
+ Hits         2741     2926     +185     
- Misses        692      817     +125     
Impacted Files Coverage Δ
packages/rum-recorder/src/domain/rrweb/mutation.ts 22.42% <ø> (ø)
packages/rum-recorder/src/domain/rrweb/observer.ts 55.02% <ø> (ø)
packages/rum-recorder/src/domain/rrweb/record.ts 60.68% <ø> (ø)
packages/rum-recorder/src/domain/rrweb/types.ts 100.00% <ø> (ø)
packages/rum-recorder/src/domain/rrweb/utils.ts 41.34% <ø> (ø)
packages/rum-recorder/src/types.ts 100.00% <ø> (ø)
...rum-recorder/src/domain/rrweb-snapshot/snapshot.ts 57.09% <57.09%> (ø)
...es/rum-recorder/src/domain/rrweb-snapshot/types.ts 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8dea89b...418a14d. Read the comment docs.

@vlad-mh vlad-mh force-pushed the vlad/embed-rrweb-snapshot branch 3 times, most recently from b080cd0 to 95115bb Compare January 27, 2021 09:27
@@ -0,0 +1,589 @@
/* eslint-disable no-underscore-dangle */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I removed some (e.g: I renamed _id to nextId), others appeared to be a more dangerous change (e.g attributes._cssText here: https://github.com/DataDog/browser-sdk/pull/700/files#diff-1c7cef52f64a686ba523420f60390086b7a16d8f13b51ac8f0a3e79d90be827eR224)

@@ -0,0 +1,589 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable @typescript-eslint/prefer-regexp-exec */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure on this.

Example: https://github.com/DataDog/browser-sdk/pull/700/files#diff-1c7cef52f64a686ba523420f60390086b7a16d8f13b51ac8f0a3e79d90be827eR349

While replacing a 'foo'.match() to /foo/.exec() makes sense, here we're talking about creating a new regexp from the return value of lowerIfExists?

Copy link
Member

Choose a reason for hiding this comment

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

I think it simply means to change

lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/)

to

/^msapplication-tile(image|color)$/.exec(lowerIfExists(sn.attributes.name))

also we could take the opportunity to change exec to test when the result is used as a boolean

/^msapplication-tile(image|color)$/.test(lowerIfExists(sn.attributes.name))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, I didn't get the string & regexp were inverted between match and exec. I'll make the change

@vlad-mh vlad-mh force-pushed the vlad/embed-rrweb-snapshot branch from 95115bb to 21d0663 Compare January 27, 2021 09:50
@vlad-mh vlad-mh marked this pull request as ready for review January 27, 2021 09:51
@vlad-mh vlad-mh requested a review from a team as a code owner January 27, 2021 09:51
@vlad-mh
Copy link
Contributor Author

vlad-mh commented Jan 27, 2021

@BenoitZugmeyer this should be ready for review 🙏

@vlad-mh vlad-mh force-pushed the vlad/embed-rrweb-snapshot branch 2 times, most recently from e9a1591 to 0bb7500 Compare January 27, 2021 11:19
const URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm
const RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/
const DATA_URI = /^(data:)([^,]*),(.*)/i
export function absoluteToStylesheet(cssText: string | null, href: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough, although this adds a dependency on jsdom and chai, are we comfortable with that? I know @BenoitZugmeyer wanted to look at importing rrweb tests in another PR

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I'm working on it. We should not import chai or jsdom though:

  • jsdom is used when running tests in Nodejs (through Jest). Since we use Karma, we can just use the real DOM
  • chai is an assertion library, karma-jasmine provides one out of the box

Copy link
Member

Choose a reason for hiding this comment

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

I think importing snapshot unit tests would be really straightforward as there is no snapshots or complex asynchronous cases. It could be worth it to import and adjust them (to use karma/jasmine) here.

return 'styleSheet' in rule
}

function extractOrigin(url: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

could we replace it by getOrigin(url: string)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getOrigin seem more complicated (builds an a element with buildUrl) compared to this implementation.
I'm not comfortable enough with JS/TS to guarantee the behavior is the same, so I'd rather not touch the code atm 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, it could worth looking into that in a separate task though

Copy link
Member

Choose a reason for hiding this comment

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

IMO for now it would make sense to keep the current implementation. As @vlad-mh stated, it is simpler and may be faster than getOrigin. Using it to transform big stylesheets seems a bit perf critical. Agreed to look into it in a future task.

return resultingSrcsetString
}

export function absoluteToDoc(doc: Document, attributeValue: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we could replace that by normalizeUrl(url: string)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could make sense, but as for https://github.com/DataDog/browser-sdk/pull/700/files/0bb750012a6e3890ce84ff315158ca404dcd5382#r565322686 I don't feel comfortable enough to make that change and guarentee I don't break things

@vlad-mh vlad-mh force-pushed the vlad/embed-rrweb-snapshot branch from cd9783f to c724d01 Compare January 27, 2021 16:52

export type SerializedNodeWithId = SerializedNode & { id: number }

export type tagMap = {
Copy link
Member

Choose a reason for hiding this comment

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

This type doesn't seem to be used. Could you remove it? else, change it to TagMap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch! latest commit removes it

@vlad-mh vlad-mh force-pushed the vlad/embed-rrweb-snapshot branch 2 times, most recently from 2a462e2 to 4a869a2 Compare February 2, 2021 09:22
@vlad-mh vlad-mh force-pushed the vlad/embed-rrweb-snapshot branch from 4a869a2 to 418a14d Compare February 2, 2021 10:53
@vlad-mh vlad-mh force-pushed the vlad/embed-rrweb-snapshot branch from 418a14d to a1a317f Compare February 2, 2021 10:55
Copy link
Contributor

@bcaudan bcaudan left a comment

Choose a reason for hiding this comment

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

LGTM

@vlad-mh vlad-mh merged commit 3e204dc into master Feb 2, 2021
@bcaudan bcaudan deleted the vlad/embed-rrweb-snapshot branch May 5, 2021 13:59
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.

4 participants