-
Notifications
You must be signed in to change notification settings - Fork 144
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
b080cd0
to
95115bb
Compare
@@ -0,0 +1,589 @@ | |||
/* eslint-disable no-underscore-dangle */ |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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.
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
?
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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
95115bb
to
21d0663
Compare
@BenoitZugmeyer this should be ready for review 🙏 |
e9a1591
to
0bb7500
Compare
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about also importing unit tests?
cf https://github.com/rrweb-io/rrweb-snapshot/blob/master/test/snapshot.test.ts
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
cd9783f
to
c724d01
Compare
|
||
export type SerializedNodeWithId = SerializedNode & { id: number } | ||
|
||
export type tagMap = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
2a462e2
to
4a869a2
Compare
4a869a2
to
418a14d
Compare
This commit removes the dependency on rrweb-snapshot and instead adds the code directly, changing the imports accordingly.
418a14d
to
a1a317f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR removes the dependency on rrweb-snapshot and instead adds it's code directly, changing the imports accordingly.