Skip to content

feat(ivy): use the schema registry to check DOM bindings#32171

Closed
alxhub wants to merge 1 commit intoangular:masterfrom
alxhub:ngtsc/ttc/schema
Closed

feat(ivy): use the schema registry to check DOM bindings#32171
alxhub wants to merge 1 commit intoangular:masterfrom
alxhub:ngtsc/ttc/schema

Conversation

@alxhub
Copy link
Member

@alxhub alxhub commented Aug 16, 2019

Previously, ngtsc attempted to use the .d.ts schema for HTML elements to
check bindings to DOM properties. However, the TypeScript lib.dom.d.ts
schema does not perfectly align with the Angular DomElementSchemaRegistry,
and these inconsistencies would cause issues in apps. There is also the
concern of supporting both CUSTOM_ELEMENTS_SCHEMA and NO_ERRORS_SCHEMA which
would have been very difficult to do in the existing system.

With this commit, the DomElementSchemaRegistry is employed in ngtsc to check
bindings to the DOM. Previous work on producing template diagnostics is used
to support generation of this different kind of error with the same high
quality of error message.


Reviewers: only the last commit is important.

@alxhub alxhub requested a review from a team August 16, 2019 23:52
@alxhub alxhub closed this Aug 16, 2019
@alxhub alxhub reopened this Aug 16, 2019
@kara kara added action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler comp: ivy labels Aug 19, 2019
@ngbot ngbot bot modified the milestone: needsTriage Aug 19, 2019
@kara kara added the target: major This PR is targeted for the next major release label Aug 19, 2019
@kara kara requested a review from JoostK August 19, 2019 16:20
Copy link
Member

Choose a reason for hiding this comment

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

How about renaming this option to checkTypeOfInputBindings?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

How about

Suggested change
const id = this.sourceManager.allocateId(sourceMapping, file);
const id = this.sourceManager.captureSource(sourceMapping, file);

or similar as it's not only allocating an id, but actually storing the source mapping data for later use.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

Could you please move TemplateSource to below TcbSourceManager, as it's the sole owner of that type. Perhaps even better would be to break out this logic into a separate file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Extracted to source.ts :) thanks, this is cleaner.

Copy link
Member

Choose a reason for hiding this comment

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

I like this refactor, now that it has substantially more usage sites :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it feels like this was a missing piece in the design.

Copy link
Member

Choose a reason for hiding this comment

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

Move import to the line above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

Could use a comment, especially how it relates to TcbUnclaimedInputsOp as these ops are queued in pairs.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 done.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.opQueue.push(new TcbSchemaCheckerOp(this.tcb, node, true, claimedInputs));
this.opQueue.push(new TcbSchemaCheckerOp(this.tcb, node, /* checkElement */ true, claimedInputs));

Copy link
Member Author

Choose a reason for hiding this comment

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

Even better, I extracted a variable with a long comment attached to it.

Copy link
Member

Choose a reason for hiding this comment

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

Include TODO comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

Loosing this test is quite unfortunate, as it's an easy feature to regress in. We could pass a full TypeCheckingConfig to tcb to keep verifying this behavior.

In general, there seems to be no remaining tests for checkTypeOfDomBindings IIUC, as it's disabled in all configurations I stumbled upon.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 reinstated the test in an experimental section.

Copy link
Member

Choose a reason for hiding this comment

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

The invocation of the DOM schema checker is currently not controlled by this flag, but only depending on the NgModule.schemas config. I believe this is the desired behavior as I mentioned in an earlier review, however can we include a note here to mention it explicitly, as any schemas configured will still check DOM bindings according to the schema.

@JoostK
Copy link
Member

JoostK commented Aug 19, 2019

As a side note, disabling the DOM bindings in the template type checker for now will "fix" several reported issues around ngBaseDef.

Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

Except for the failing Material tests and a minor comment, LGTM!

Copy link
Member

Choose a reason for hiding this comment

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

Oops, looks like a bad rebase. Could you restore this test and the one below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually this change was intentional - these tests as written tested the behavior when binding to properties of plain DOM elements. But you're right, their functionality is relevant for binding to directive inputs as well, so I've ported them to test that instead.

Previously, ngtsc attempted to use the .d.ts schema for HTML elements to
check bindings to DOM properties. However, the TypeScript lib.dom.d.ts
schema does not perfectly align with the Angular DomElementSchemaRegistry,
and these inconsistencies would cause issues in apps. There is also the
concern of supporting both CUSTOM_ELEMENTS_SCHEMA and NO_ERRORS_SCHEMA which
would have been very difficult to do in the existing system.

With this commit, the DomElementSchemaRegistry is employed in ngtsc to check
bindings to the DOM. Previous work on producing template diagnostics is used
to support generation of this different kind of error with the same high
quality of error message.
@alxhub alxhub 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 21, 2019
@alxhub
Copy link
Member Author

alxhub commented Aug 21, 2019

@AndrewKushnir this could probably use an Ivy global presubmit prior to landing, just to make sure it doesn't break any apps in g3.

@AndrewKushnir AndrewKushnir added the action: presubmit The PR is in need of a google3 presubmit label Aug 21, 2019
@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Aug 22, 2019

@atscott atscott closed this in 0677cf0 Aug 22, 2019
@kara kara removed the action: presubmit The PR is in need of a google3 presubmit label Aug 22, 2019
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
Previously, ngtsc attempted to use the .d.ts schema for HTML elements to
check bindings to DOM properties. However, the TypeScript lib.dom.d.ts
schema does not perfectly align with the Angular DomElementSchemaRegistry,
and these inconsistencies would cause issues in apps. There is also the
concern of supporting both CUSTOM_ELEMENTS_SCHEMA and NO_ERRORS_SCHEMA which
would have been very difficult to do in the existing system.

With this commit, the DomElementSchemaRegistry is employed in ngtsc to check
bindings to the DOM. Previous work on producing template diagnostics is used
to support generation of this different kind of error with the same high
quality of error message.

PR Close angular#32171
@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 22, 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 area: compiler Issues related to `ngc`, Angular's template compiler cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants