Sitelet https://github.com/angular/angular/pull/70388
Skip to content

refactor(core): defer foreign component rendering to post-update pass - #70388

Open
leonsenft wants to merge 1 commit into
angular:mainfrom
leonsenft:defer_foreign_component_render
Open

refactor(core): defer foreign component rendering to post-update pass#70388
leonsenft wants to merge 1 commit into
angular:mainfrom
leonsenft:defer_foreign_component_render

Conversation

@leonsenft

@leonsenft leonsenft commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Foreign components imported via foreignImports and created by the ɵɵforeignComponent instruction were previously rendered eagerly in the creation phase (rf & 1) of the template. This restricted which properties could be passed to foreign component props, as parent-bound inputs (@Input(), input(), input.required()), properties initialized in ngOnInit(), and view queries (viewChild(), @ViewChild()) were not yet initialized at creation time.

This change defers foreign component rendering to the end of the view update pass:

  • Update ɵɵforeignComponent in core to schedule component rendering via EFFECTS_TO_SCHEDULE at the end of the update pass (refreshView), executed within untracked() to prevent reactive context leakage.
  • Update ɵɵforeignComponent to strictly accept props as a factory function ((() => props) | null).
  • Update the compiler template pipeline to wrap foreign component props in an arrow function closure (() => ({ ... })).
  • Hoist creation-time foreign content projection instructions (ɵɵforeignContent, ɵɵforeignContentFn) into creation-phase variable declarations before ɵɵforeignComponent so creation-time context is captured safely.
  • Immediately refresh embedded views created for projected foreign content so control flow and child bindings evaluate on initial render.

@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Aug 25, 2026
@ngbot ngbot Bot added this to the Backlog milestone Aug 25, 2026
@leonsenft
leonsenft force-pushed the defer_foreign_component_render branch 3 times, most recently from 1a7dfcb to ffaf0a5 Compare August 25, 2026 21:30
@leonsenft
leonsenft requested a review from alxhub August 25, 2026 21:33
Foreign components imported via foreignImports and created by the
ɵɵforeignComponent instruction were previously rendered eagerly in the
creation phase (rf & 1) of the template. This restricted which
properties could be passed to foreign component props, as parent-bound
inputs (@input(), input(), input.required()), properties initialized in
ngOnInit(), and view queries (viewChild(), @ViewChild()) were not yet
initialized at creation time.

This change defers foreign component rendering to the end of the view
update pass:
- Update ɵɵforeignComponent in core to schedule component rendering via
  EFFECTS_TO_SCHEDULE at the end of the update pass (refreshView),
  executed within untracked() to prevent reactive context leakage.
- Update ɵɵforeignComponent to strictly accept props as a factory function
  (() => props) or null.
- Update the compiler template pipeline to wrap foreign component props
  in an arrow function closure (() => ({ ... })).
- Hoist creation-time foreign content projection instructions
  (ɵɵforeignContent, ɵɵforeignContentFn) into creation-phase variable
  declarations before ɵɵforeignComponent so creation-time context is
  captured safely.
- Immediately refresh embedded views created for projected foreign
  content so control flow and child bindings evaluate on initial render.
@leonsenft
leonsenft force-pushed the defer_foreign_component_render branch from ffaf0a5 to 69b1369 Compare August 25, 2026 21:55
@leonsenft leonsenft added the target: patch This PR is targeted for the next patch release label Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant