feat: allow deferred attaching and applying of properties during CD#173
Open
edusperoni wants to merge 1 commit into
Open
feat: allow deferred attaching and applying of properties during CD#173edusperoni wants to merge 1 commit into
edusperoni wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
b45830b to
17b6fb1
Compare
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.
PR Checklist
What is the current behavior?
During Angular change detection, the renderer applies every native side-effect synchronously and individually: each native property/style/class write happens as the binding is evaluated, and each view is attached to the native (visual) tree the moment it is appended — which is what triggers it to load (create its native view and measure/lay out). For a CD pass that builds or churns a subtree, this means views load incrementally into a live parent, native property setters can run while a subtree is still half-built, and a view created and removed within the same CD pass still loads.
What is the new behavior?
Adds an opt-in mode that batches native side-effects produced during change detection and applies them once, when CD finishes.
RendererFactory2.begin()/end()(which Angular calls around every CD pass) to open/flush a deferral window.parentNode/firstChild/nextSibling/…) is still updated synchronously, so navigation and ordering are unaffected.Benefits when enabled:
Opt in via the bootstrap config:
or by providing the
DEFER_NATIVE_OPS_DURING_CDtoken directly. It is off by default, so there is no behavior change unless explicitly enabled.Tests: added a renderer test suite (
renderer-tests.spec.ts) covering the deferral mechanics (deferred attach with synchronous logical tree, add-then-remove elimination, right-to-left insertion, moves, property/class coalescing, leftover-flush recovery, load-exactly-once), the feature's inert default, and end-to-end Angular control-flow rendering (@if/@forwithtrack). Also restored/modernized the previously commented-out renderer tests (createElement, attach/detach, listen, component structure, projection, styles).