New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ivy): support injecting Renderer2 #25523
Conversation
@@ -318,6 +326,8 @@ export function dependenciesFromGlobalMetadata( | |||
resolved = R3ResolvedDependencyType.Injector; | |||
} else if (dependency.isAttribute) { | |||
resolved = R3ResolvedDependencyType.Attribute; | |||
} else if (tokenRef === renderer2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be immediately following the other tokenRef
guards above, its location below dependency.isAttribute
seems a bit out of line to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
selectorOrNode; | ||
} | ||
|
||
parentNode(node: RNode): RNode { return (node as any).parentNode; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return type can't be correct, as the root node doesn't have a parent. Should include undefined
or null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
if (target === 'window') { | ||
targetElement = window; | ||
} else if (target === 'document') { | ||
targetElement = this.renderer as Document; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't it possible for the renderer to be different across views? That would mean this isn't always the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the API (event target as a string) is way too DOM specific. In fact, I think it shouldn't be supported in such an adapter.
packages/core/src/render3/di.ts
Outdated
if (!di.renderer2) { | ||
const renderer = di.node.view[RENDERER]; | ||
di.renderer2 = | ||
isProceduralRenderer(renderer) ? renderer as Renderer2 : new Renderer2Adapter(renderer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I like that we have made Renderer2Adapter
non tree-shakable. I think we should just return null
. If your app wants Render2
we should bootstrap with Render2
rather than always pool in Renderer2Adapter
which wont be used in vast majority of cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the drawback yes.
If we don't have this adapter, that would be a breaking change. Apps might crash at runtime if they move from Renderer2 to Renderer3, because themselves or one of their dependencies injects Renderer2.
@@ -83,6 +84,9 @@ export interface LInjector { | |||
* same instance. | |||
*/ | |||
changeDetectorRef: ChangeDetectorRef|null; | |||
|
|||
/** Stores the Renderer2 so subsequent injections of the Renderer2 get the same instance. */ | |||
renderer2: Renderer2|null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to store this since it is same as view[RENDERER]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
'xmlns': 'http://www.w3.org/2000/xmlns/', | ||
}; | ||
|
||
export class Renderer2Adapter extends Renderer2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this. I would just revert this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's discuss this
477b6a2
to
f37d5c7
Compare
You can preview f37d5c7 at https://pr25523-f37d5c7.ngbuilds.io/. |
f37d5c7
to
3fcc4e2
Compare
You can preview 3fcc4e2 at https://pr25523-3fcc4e2.ngbuilds.io/. |
3fcc4e2
to
c4a85e8
Compare
You can preview c4a85e8 at https://pr25523-c4a85e8.ngbuilds.io/. |
c4a85e8
to
0f8c425
Compare
You can preview 0f8c425 at https://pr25523-0f8c425.ngbuilds.io/. |
0f8c425
to
00b6c41
Compare
You can preview 00b6c41 at https://pr25523-00b6c41.ngbuilds.io/. |
00b6c41
to
2ae0bb8
Compare
You can preview 2ae0bb8 at https://pr25523-2ae0bb8.ngbuilds.io/. |
2ae0bb8
to
9250e99
Compare
You can preview 9250e99 at https://pr25523-9250e99.ngbuilds.io/. |
9250e99
to
c887a36
Compare
You can preview c887a36 at https://pr25523-c887a36.ngbuilds.io/. |
@mhevery PR rebased and updated to your comments, PTAL |
c887a36
to
9550aec
Compare
You can preview 9550aec at https://pr25523-9550aec.ngbuilds.io/. |
9550aec
to
1eeb701
Compare
You can preview 1eeb701 at https://pr25523-1eeb701.ngbuilds.io/. |
1eeb701
to
6995caf
Compare
You can preview 6995caf at https://pr25523-6995caf.ngbuilds.io/. |
6995caf
to
286772b
Compare
You can preview 286772b at https://pr25523-286772b.ngbuilds.io/. |
d81f211
to
f4a43ba
Compare
You can preview d81f211 at https://pr25523-d81f211.ngbuilds.io/. |
You can preview f4a43ba at https://pr25523-f4a43ba.ngbuilds.io/. |
f4a43ba
to
ee6a132
Compare
You can preview ee6a132 at https://pr25523-ee6a132.ngbuilds.io/. |
http://test/OCL:210564490:BASE:210564566:1535477659881:35f16132 caretaker please check above and merge |
ee6a132
to
4dea0d2
Compare
You can preview 4dea0d2 at https://pr25523-4dea0d2.ngbuilds.io/. |
4dea0d2
to
5885b2d
Compare
You can preview 5885b2d at https://pr25523-5885b2d.ngbuilds.io/. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This PR adds support for injecting
Renderer2
.The
Renderer2Adapter
class is almost a copy/paste of theDefaultDomRenderer2
class that we have in the platorm-browser package, but without dependencies toEventManager
andNgZone
.It feels wrong, but at the same time a
ObjectOrientedRenderer3
is not linked to the DOM, in theory. The adapter should only know aboutRnode
s.About the changes in the compiler, this is the first time I do some. So please review them carefully.