🎨 [PANA-5053] Separate DOM and virtual attribute serialization #3998
+72
−80
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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