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

perf(router-plugin): tree-shake isAngularInTestMode() #1738

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
perf(router-plugin): tree-shake isAngularInTestMode()
arturovt committed Apr 27, 2021

Verified

This commit was signed with the committer’s verified signature.
jalaziz Jameel Al-Aziz
commit 30c45a9cc7ee3bc417f8f1383ef1c0589de2caa7
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ $ npm install @ngxs/store@dev

- Fix: Allow to inject the `Store` into the custom error handler [#1708](https://github.com/ngxs/store/pull/1708)
- Performance: Tree-shake errors and warnings [#1732](https://github.com/ngxs/store/pull/1732)
- Performance: Router Plugin - Tree-shake `isAngularInTestMode()` [#1733](https://github.com/ngxs/store/pull/1733)
- Performance: Storage Plugin - Tree-shake `console.*` calls and expand error messages [#1727](https://github.com/ngxs/store/pull/1727)
- CI: Add bundlesize check for the latest integration app [#1710](https://github.com/ngxs/store/pull/1710)

2 changes: 1 addition & 1 deletion integrations/hello-world-ng11-ivy/bundlesize.config.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
{
"path": "./dist-integration/main.*.js",
"target": "es2015",
"maxSize": "251.70 kB",
"maxSize": "251.35 kB",
"compression": "none"
}
]
15 changes: 14 additions & 1 deletion packages/router-plugin/src/router.state.ts
Original file line number Diff line number Diff line change
@@ -33,6 +33,12 @@ export interface RouterStateModel<T = RouterStateSnapshot> {

export type RouterTrigger = 'none' | 'router' | 'store';

/**
* @description Will be provided through Terser global definitions by Angular CLI
* during the production build. This is how Angular does tree-shaking internally.
*/
declare const ngDevMode: boolean;

@State<RouterStateModel>({
name: 'router',
defaults: {
@@ -233,7 +239,14 @@ export class RouterState {
* is triggered
*/
private checkInitialNavigationOnce(): void {
if (isAngularInTestMode()) {
// Caretaker note: we have still left the `typeof` condition in order to avoid
// creating a breaking change for projects that still use the View Engine.
if (
(typeof ngDevMode === 'undefined' || ngDevMode) &&
// Angular is running tests in development mode thus we can be sure that this method will be
// skipped in tests.
isAngularInTestMode()
) {
return;
}