♻️ [PANA-7375] Eliminate unnecessary conditional node serialization#4629
Open
sethfowler-datadog wants to merge 1 commit into
Conversation
mormubis
approved these changes
May 15, 2026
6cb3215 to
cdf7f69
Compare
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: cdf7f69 | Docs | Datadog PR Page | Give us feedback! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
There's an awkward edge case that exists today: in very narrow circumstances, we decline to serialize nodes when "bulk serializing" a DOM subtree based on certain conditions, but we will serialize those exact same nodes if they're mutated later.
This breaks some invariants that you'd expect to hold. For example, you'd expect that if you encounter an unserialized node, then one of these three things must be true:
Conditional serialization adds a fourth, non-obvious case to this list.
Similarly (and this is a case I had reason to care about recently), you might expect that this sequence of actions:
Would be guaranteed to produce the same final rendering as this sequence of actions:
However, today, this isn't necessarily so! That's because we apply conditional serialization to text nodes, and changing the text content of a text node can change whether it's included in the full snapshot. If it's not included, subsequent incremental mutations won't be captured either, even if the condition is satisfied as a result of the change. However, the next time a full snapshot is taken, the node will reappear -- hence the reason why the two sequences of action above can produce different results.
We should view this as a bug. There are two ways we could fix it:
I've chosen path #2; given the very limited circumstances in which we apply conditional serialization, and the very limited benefit we obtain from it, I think the best path forward is simply to remove it and eliminate this source of complexity.
Changes
We conditionally decline to serialize nodes in two circumstances today:
<head>are not serialized if they contain only whitespace.<datalist>,<select>, or<optgroup>are not serialized if they contain only whitespace and they would otherwise be masked.In both of these situations, we now unconditionally serialize the nodes.
Checklist