-
Notifications
You must be signed in to change notification settings - Fork 2
Description
The problem:
If a rule change the URL, this dispatch the URL change internally, if another rule changes it again, it might start a infinite recursive loop of changes.
No browser doesn't detect such changes and will crash at some point.
The solution:
Create a stack limit of URL changes inside the dispatch, and throw Stackoverflow URL changes error them stop all current routers dispatch process, throw error event it every router, and disable all the router instances without executing any rule.
This is like a kill switch, if it happens the website will stop working but the browser won't freeze.
Motivation:
Because the nature of PushStateTree, it's very normal to developers when begin to use it create recursive URL redirects, and it's super annoying when this happens because the browser freezes and it's so hard to debug and fix.
Implementation detail:
The must common scenario are implementations that repeat the same URL at some point and start the a infinite loop, however we can't trust that as universal truth, because a implementation can never repeat the same URL and be a infinite loop of changes.
That said, we should not test for URL that were already executed, because we can't trust in the developer implementation. Like he can create a recursive URL change that never repeats the URL.
Tests:
- Any event on router or rule triggers URL change for 20 consecutive times before leave the dispatch execution must throw this exception.