-
Notifications
You must be signed in to change notification settings - Fork 166
🎨 [PANA-5053] Separate DOM and virtual attribute serialization #3998
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
🎨 [PANA-5053] Separate DOM and virtual attribute serialization #3998
Conversation
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 worries me is the removal of getValidTagName. I know it's probably a stretch nowadays, but if one of our customer still serves their application using application/xhtml+xml, wouldn't the tag names be lower case?
Yes, indeed that is still possible. (I double checked the behavior with this site, which I am linking for posterity because it's incredibly hard to find any site that's served using We are unfortunately already checking only for uppercase tag names in many places in the code, so I don't think the SDK will behave correctly on XHTML sites today, but I think it's worth keeping the things that work today working. We can do that without the full weight of |
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
|
Motivation
The current DOM serialization algorithm produces two kinds of attributes on elements:
foo="bar"in<div foo="bar">.rr_scrollLeftandrr_scrollTopare used to capture information about the initial scroll position of an element.Many of these virtual attributes are primarily of interest in full snapshots; later, when the values change incrementally, we represent them using dedicated records. For example, later changes to
rr_scrollLeftandrr_scrollTopare represented asBrowserIncrementalSnapshotRecordrecords withIncrementalSource.Scroll. (Speculating on the reasoning for the different representation in full snapshots, I'd guess this was done because there's no easy way to bundle multiple changes into a single, atomic full snapshot record except to include them in the DOM snapshot itself. Incremental snapshots can bundle together many changes at once, so they don't have the same issue.)The new DOM serialization algorithm doesn't have a special record type for full snapshots; everything uses a representation comparable to our current incremental snapshots. For that reason, the new algorithm doesn't need these virtual attributes; it makes more sense to encode these values in the same way we do today for incremental snapshots.
To make it easier to share code between the current DOM serialization algorithm and the new one, let's separate the code that serializes real DOM attributes from the code that serializes virtual attributes.
Changes
This PR:
safeAttrstoattrsinserializeAttributes()as a minor opportunistic refactor. I'm not a big fan of the namesafeAttrssince it implies that everything insafeAttrssatisfies our privacy rules and is safe to record, but in fact that's not true until the end of the function.serializeAttributes()into two functions,serializeDOMAttributes()andserializeVirtualAttributes(). (serializeAttributes()survives as a trivial wrapper around these two functions.)serializeDOMAttributes()can now return.getValidTagName()from both functions since it contains a regular expression which it would be wasteful to invoke in two places.getValidTagName()doesn't really provide any benefit since we are only comparing the tag name with exact known strings in this code; we can just useElement#tagNamedirectly.serializeAttributes()to callserializeDOMAttributes()orserializeVirtualAttributes(), as appropriate. (I wrote the tests with this in mind, so making the switch is easy.)Checklist