mgechev / mgechev/ngx-quicklink

Race condition on redirect 'Cannot read property 'routes' of undefined'

Open
#73 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
757
Forks
43
PR merge metrics
No merged PRs in 30d

Description

Hi and thanks for the library.
But I have an issue 😬

### Description

For example, we have a categories page (lazy module) and when we click on "Categories" link in navigation we want to redirect to default category "Books" (lazy module).
How navigation looks:
Home
— Categories
— Books

The intersection observer emits 3 links sequentially and passes them to requestIdleCallback.

1. Router skips first link '/' because we don't have `loadChildren` property in the router config
2. Router starts loading of a module associated with '/categories' link
3. Strategy doesn't wait until '/categories' loaded and removes '/categories/books' from the list of trees (`this.queue.remove(...)`)

So after `CategoriesModule` loaded strategy doesn't load `BooksModule` .
Last but not least if we go to page 'categories/books' and manually reload the page (cmd + r) we may get the error '*Cannot read property routes of undefined*'. The error is not permanent and more often appears in FireFox and always appears at a slow network (you can get it if setup throttling to 4G in network tab).

### Minimal Reproduction
Repo - [https://github.com/Komock/quick-link-test](https://github.com/Komock/quick-link-test)
Demo - [https://komock.github.io/quick-link-test/](https://komock.github.io/quick-link-test/)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked quick-link-test reproduction and reproduce the failure with network throttling, focusing on the sequence involving loadChildren and this.queue.remove(...). Verify the behavior while navigating to categories/books and reloading it; done means both lazy modules load without the routes error.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.