[Fizz] Add separator comment between text nodes #21099
Merged
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.
This is needed to avoid mutating the DOM during hydration.
This always adds it even when it's just text children. We need to avoid this overhead but it's a somewhat tricky problem to solve so we defer the optimization to later. This is also related to #13342 which is similarly difficult.
The thing that makes this difficult in Fizz is that there might be a segment that is currently suspended that may or may not render text nodes. Before or After this text node. Or there can be consecutive suspended components that resolve in various order.
We also want the result to be deterministic so if we can't always optimize it away, regardless of if/when those things resolve, then we should always insert it.
We could possible do the determination when segments resolve but then they need pointers to their parents and siblings.
I think there's a way to solve this by determining whether to emit a separator is done at the flush stage. It adds more computation there and unfortunately we'd need data structures that likely affects all "renderers".
Dropping the determinism constraint might also be an option (id-generation isn't atm).