refactor(core): add context support for foreign components#69502
Closed
leonsenft wants to merge 3 commits into
Closed
refactor(core): add context support for foreign components#69502leonsenft wants to merge 3 commits into
leonsenft wants to merge 3 commits into
Conversation
cd635e0 to
b23131f
Compare
Enable foreign components to receive and propagate contextual data across framework boundaries. Previously, foreign render functions only accepted component properties, and foreign content projection instructions (`ɵɵforeignContent` / `ɵɵforeignContentFn`) did not provide any mechanism to expose foreign framework context to projected Angular embedded views. With this change: - Update `ForeignRenderFn` and `ForeignComponent` interfaces to accept an optional context parameter and an optional `GET_CONTEXT` symbol method. - Introduce `FOREIGN_CONTEXT` injection token and `provideForeignRootContext` helper to configure root context in Angular's DI hierarchy. - Update `ɵɵforeignComponent` instruction to resolve `FOREIGN_CONTEXT` from the injection tree and pass it to the foreign component's render function. - Update `ɵɵforeignContent` and `ɵɵforeignContentFn` instructions to wrap embedded view creation with a `ForeignContextInjector` when `GET_CONTEXT` is present. Furthermore, foreign render functions are no longer run inside an Angular injection context, since it's expected they use the foreign context support directly.
`@content(name)` -> `@content (name)` to align with other block syntax.
b23131f to
0f319a0
Compare
alxhub
approved these changes
Jun 29, 2026
| * @param contextFactory The factory function that creates the root context object. | ||
| * @template TContext The foreign context type. | ||
| */ | ||
| export function provideForeignRootContext<TContext>(contextFactory: () => TContext): Provider { |
Member
There was a problem hiding this comment.
This limits us to a singleton foreign context per application, right? So if we ended up in an app with multiple foreign frameworks, things would break down.
One way around this is to have a global Map<string, InjectionToken<unknown>> that maintains a token-per-stringly-typed-framework, and accept the framework name in provideForeignRootContext. This assumes we can identify the foreign framework at the usage site in order to look up this key.
Contributor
Author
There was a problem hiding this comment.
Yes, that's a great suggestion. I'll work on this in a follow-up PR.
Member
|
This PR was merged into the repository. The changes were merged into the following branches:
|
alxhub
pushed a commit
that referenced
this pull request
Jun 30, 2026
`@content(name)` -> `@content (name)` to align with other block syntax. PR Close #69502
6 tasks
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.
Enable foreign components to receive and propagate contextual data across framework boundaries.
Previously, foreign render functions only accepted component properties, and foreign content projection instructions (
ɵɵforeignContent/ɵɵforeignContentFn) did not provide any mechanism to expose foreign framework context to projected Angular embedded views.With this change:
Update
ForeignRenderFnandForeignComponentinterfaces to accept an optional context parameter and an optionalGET_CONTEXTsymbol method.Introduce
FOREIGN_CONTEXTinjection token andprovideForeignRootContexthelper to configure root context in Angular's DI hierarchy.Update
ɵɵforeignComponentinstruction to resolveFOREIGN_CONTEXTfrom the injection tree and pass it to the foreign component's render function.Update
ɵɵforeignContentandɵɵforeignContentFninstructions to wrap embedded view creation with aForeignContextInjectorwhenGET_CONTEXTis present.Furthermore, foreign render functions are no longer run inside an Angular injection context, since it's expected they use the foreign context support directly.