scullyio / scully

The Static Site Generator for Angular apps
https://scully.io/
MIT License
2.55k stars 256 forks source link

Route params can cause TransferState error #581

Closed donmckenna closed 4 years ago

donmckenna commented 4 years ago

🐞 Bug report

Description

TransferStateService.useScullyTransferState() seems to cause fetchTransferState() to throw an error when navigating from a route without params to a route with params..
but only when refreshing the page on a route without params..
and not when refreshing the page on a route with params.

The result of the useScullyTransferState observable seems to behave differently depending on the route which Angular is freshly loaded from.

🔬 Minimal Reproduction

Step by step in the README. The error reveals itself when navigating in specific steps.

Repo: https://github.com/donmckenna/scully-transferState Live Example: https://wizardly-johnson-148805.netlify.app/

💻Your Environment

Angular Version:

Angular CLI: 9.1.7
Node: 12.16.3
OS: win32 x64

Angular: 9.1.9
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.7
@angular-devkit/build-angular     0.901.7
@angular-devkit/build-optimizer   0.901.7
@angular-devkit/build-webpack     0.901.7
@angular-devkit/core              9.1.7
@angular-devkit/schematics        9.1.7
@angular/cli                      9.1.7
@ngtools/webpack                  9.1.7
@schematics/angular               9.1.7
@schematics/update                0.901.7
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

Scully Version:

"@scullyio/init": "0.0.28",
"@scullyio/ng-lib": "latest",
"@scullyio/scully": "latest",

🔥 Exception or Error

ERROR TypeError: Cannot read property 'transferStateTest' of null
at MapSubscriber.mapper [as project] (pluck.js:13)
at MapSubscriber._next (map.js:29)
at MapSubscriber.next (Subscriber.js:49)
at FilterSubscriber._next (filter.js:33)
at FilterSubscriber.next (Subscriber.js:49)
at BehaviorSubject.next (Subject.js:39)
at BehaviorSubject.next (BehaviorSubject.js:30)
at TapSubscriber._tapNext (scullyio-ng-lib.js:398)
at TapSubscriber._next (tap.js:40)
at TapSubscriber.next (Subscriber.js:49)
SanderElias commented 4 years ago

fixed in #517