Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

marclaval
Copy link
Contributor

This PR adds support for injecting Renderer2.

The Renderer2Adapter class is almost a copy/paste of the DefaultDomRenderer2 class that we have in the platorm-browser package, but without dependencies to EventManager and NgZone.
It feels wrong, but at the same time a ObjectOrientedRenderer3 is not linked to the DOM, in theory. The adapter should only know about Rnodes.

About the changes in the compiler, this is the first time I do some. So please review them carefully.

@marclaval marclaval added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release comp: ivy labels Aug 16, 2018
@@ -318,6 +326,8 @@ export function dependenciesFromGlobalMetadata(
resolved = R3ResolvedDependencyType.Injector;
} else if (dependency.isAttribute) {
resolved = R3ResolvedDependencyType.Attribute;
} else if (tokenRef === renderer2) {
Copy link
Member

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.

Copy link
Contributor Author

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; }
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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.

if (!di.renderer2) {
const renderer = di.node.view[RENDERER];
di.renderer2 =
isProceduralRenderer(renderer) ? renderer as Renderer2 : new Renderer2Adapter(renderer);
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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]

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discuss this

@mary-poppins
Copy link

You can preview f37d5c7 at https://pr25523-f37d5c7.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 3fcc4e2 at https://pr25523-3fcc4e2.ngbuilds.io/.

@mary-poppins
Copy link

You can preview c4a85e8 at https://pr25523-c4a85e8.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 0f8c425 at https://pr25523-0f8c425.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 00b6c41 at https://pr25523-00b6c41.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 2ae0bb8 at https://pr25523-2ae0bb8.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 9250e99 at https://pr25523-9250e99.ngbuilds.io/.

@mary-poppins
Copy link

You can preview c887a36 at https://pr25523-c887a36.ngbuilds.io/.

@marclaval
Copy link
Contributor Author

@mhevery PR rebased and updated to your comments, PTAL

@mary-poppins
Copy link

You can preview 9550aec at https://pr25523-9550aec.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 1eeb701 at https://pr25523-1eeb701.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 6995caf at https://pr25523-6995caf.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 286772b at https://pr25523-286772b.ngbuilds.io/.

@marclaval marclaval force-pushed the injectRenderer2 branch 2 times, most recently from d81f211 to f4a43ba Compare August 27, 2018 16:22
@mary-poppins
Copy link

You can preview d81f211 at https://pr25523-d81f211.ngbuilds.io/.

@mary-poppins
Copy link

You can preview f4a43ba at https://pr25523-f4a43ba.ngbuilds.io/.

@mary-poppins
Copy link

You can preview ee6a132 at https://pr25523-ee6a132.ngbuilds.io/.

@mhevery mhevery added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 28, 2018
@mhevery
Copy link
Contributor

mhevery commented Aug 28, 2018

http://test/OCL:210564490:BASE:210564566:1535477659881:35f16132

caretaker please check above and merge

@mhevery mhevery added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Aug 28, 2018
@mary-poppins
Copy link

You can preview 4dea0d2 at https://pr25523-4dea0d2.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 5885b2d at https://pr25523-5885b2d.ngbuilds.io/.

@marclaval marclaval removed the request for review from alxhub August 31, 2018 15:54
@mhevery mhevery closed this in 00f1311 Aug 31, 2018
petebacondarwin pushed a commit to petebacondarwin/angular that referenced this pull request Sep 3, 2018
FrederikSchlemmer pushed a commit to FrederikSchlemmer/angular that referenced this pull request Jan 3, 2019
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants