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

refactor(core): make the error messages tree shakable #44219

Closed
wants to merge 1 commit into from
Closed

refactor(core): make the error messages tree shakable #44219

wants to merge 1 commit into from

Conversation

ramthir
Copy link
Contributor

@ramthir ramthir commented Nov 19, 2021

Long error messages can be tree-shaken in the production build.
Doing this, we will keep the throw and remove the long error messages.

See: #44210 (review)

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Long error messages are not tree-shakable in the production build.

Issue Number: N/A

What is the new behavior?

Long error messages are made tree-shakable in the production build based on the suggestion by @AndrewKushnir in PR 44210.

For constancy, I've done this change on all the error messages in application_ref.ts. @AndrewKushnir, please check if it's necessary.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@google-cla google-cla bot added the cla: yes label Nov 19, 2021
@pullapprove pullapprove bot requested a review from alxhub November 19, 2021 03:06
@AndrewKushnir AndrewKushnir requested review from AndrewKushnir and removed request for alxhub November 19, 2021 16:44
@AndrewKushnir AndrewKushnir added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: core Issues related to the framework runtime labels Nov 19, 2021
@ngbot ngbot bot added this to the Backlog milestone Nov 19, 2021
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@ramthir thanks for creating this PR 👍 The changes look good, I've just added a couple comments.

I've also noticed that the CI is failing and the error message indicates the positive impact of this change: bundles for the test apps decreased, see this CI job output:

FAIL: Commit undefined uncompressed main fell below
expected size by 500 bytes or >1% (expected: 139282, actual: 138491).

So this change helped reduce the bundle size by ~800 bytes (which is great!). Could you please take a look at the failing CI jobs and update payload size limits according to the actual bundle sizes, mentioned in the CI output? Please let me know if any additional information is needed on this.

packages/core/src/application_ref.ts Outdated Show resolved Hide resolved
packages/core/src/application_ref.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@ramthir thanks for resolving merge conflicts! We've discussed this PR with the team and I've left a couple comments with some feedback. Thank you.

packages/core/src/application_ref.ts Outdated Show resolved Hide resolved
packages/core/src/application_ref.ts Outdated Show resolved Hide resolved
packages/core/src/application_ref.ts Show resolved Hide resolved
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@ramthir thanks for updating the PR, the changes look very good and we are very close. I've just added a couple more comments.

packages/core/src/application_ref.ts Show resolved Hide resolved
packages/core/src/application_ref.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Thanks for applying the necessary updates @ramthir 👍

The changes look good and I've also rebased the PR (the setup CI job was failing). We'll need to get one more review on this PR and run extra tests in Google's codebase (I will take care of this). I will keep you updated on how it goes.

@AndrewKushnir AndrewKushnir added the action: presubmit The PR is in need of a google3 presubmit label Nov 26, 2021
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Reviewed-for: size-tracking

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Reviewed-for: size-tracking

@ramthir it looks like the test CI job is failing with size-related reasons:

FAIL: Commit undefined uncompressed main fell below expected size
by 500 bytes or >1% (expected: 237238, actual: 230506).

Could you please update the golden as I mentioned in the comment below?

goldens/size-tracking/integration-payloads.json Outdated Show resolved Hide resolved
Long error messages can be tree-shaken in the production build.
Doing this, we will keep the throw and remove the long error messages.

See: #44210 (review)
@AndrewKushnir
Copy link
Contributor

One more run of tests in Google's codebase (internal-only link).

Copy link
Contributor

@dylhunn dylhunn left a comment

Choose a reason for hiding this comment

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

reviewed-for: size-tracking

@dylhunn
Copy link
Contributor

dylhunn commented Nov 30, 2021

@AndrewKushnir The presubmit you ran has one new failure (a hume target) -- have you looked at that at all? It seems to be unrelated to this change so it's likely a flake

Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

Choose a reason for hiding this comment

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

LGTM 🍪

reviewed-for: size-tracking

throw new Error(
'There can be only one platform. Destroy the previous one to create a new one.');
const errorMessage = (typeof ngDevMode === 'undefined' || ngDevMode) ?
'There can be only one platform. Destroy the previous one to create a new one.' :
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you didn't write this line, but I hope whomever did write it initially was referencing Highlander.

@AndrewKushnir AndrewKushnir removed action: review The PR is still awaiting reviews from at least one requested reviewer action: presubmit The PR is in need of a google3 presubmit labels Nov 30, 2021
@AndrewKushnir
Copy link
Contributor

The presubmit you ran has one new failure (a hume target) -- have you looked at that at all? It seems to be unrelated to this change so it's likely a flake

@dylhunn yeah, that was a flake, I've restarted that test and everything is now fully "green" and this PR is ready for merge.

@AndrewKushnir AndrewKushnir added the action: merge The PR is ready for merge by the caretaker label Nov 30, 2021
@dylhunn
Copy link
Contributor

dylhunn commented Nov 30, 2021

This PR was merged into the repository by commit 96dfc7a.

@dylhunn dylhunn closed this in 96dfc7a Nov 30, 2021
dylhunn pushed a commit that referenced this pull request Nov 30, 2021
Long error messages can be tree-shaken in the production build.
Doing this, we will keep the throw and remove the long error messages.

See: #44210 (review)

PR Close #44219
@ramthir ramthir deleted the application-ref-throw-tree-shaking branch November 30, 2021 23:58
@AndrewKushnir
Copy link
Contributor

@ramthir thanks for contributing to Angular, this change will have a positive impact on all Angular applications (the ApplicationRef class is used under the hood for all apps)! 👍

If you are interested in creating more PRs, there are some other places that would benefit from a similar change, for example:

Also a few places in the following files (search for throw new Error):

  • packages/core/src/di/injector_compatibility.ts
  • packages/core/src/di/r3_injector.ts
  • packages/core/src/render3/view_ref.ts
  • packages/core/src/render3/features/inherit_definition_feature.ts
  • packages/core/src/render3/i18n/i18n_apply.ts
  • packages/core/src/sanitization/sanitization.ts

I'm also exploring a possible solution to make the RuntimeError class reusable in other packages (currently it's only available in core) and will create a PR at some point.

@ramthir
Copy link
Contributor Author

ramthir commented Dec 1, 2021

Thanks a lot, @AndrewKushnir; I'll look up and raise PRs on them.

dimakuba pushed a commit to dimakuba/angular that referenced this pull request Dec 28, 2021
Long error messages can be tree-shaken in the production build.
Doing this, we will keep the throw and remove the long error messages.

See: angular#44210 (review)

PR Close angular#44219
@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 Jan 1, 2022
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: core Issues related to the framework runtime area: performance cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants