Skip to content

Async navigation cancelation - #826

Merged
internettrans merged 7 commits into
6.0from
async-cancel-navigation
Jul 6, 2021
Merged

Async navigation cancelation#826
internettrans merged 7 commits into
6.0from
async-cancel-navigation

Conversation

@internettrans

@internettrans internettrans commented Jul 6, 2021

Copy link
Copy Markdown
Member

Resolves #670. I started with the code from @cjpearson in #689 and finished out the implementation, including adding tests.

This is a breaking change, as single-spa events are no longer fired for the reroute caused by cancelation, and also the navigationIsCanceled boolean is removed from all custom event detail objects (since it's never true anymore due to events no longer being fired after cancelation occurs). Since it's breaking, I have it merging into the 6.0 branch rather than the master branch.

@internettrans
internettrans changed the base branch from master to 6.0 July 6, 2021 00:21
@github-actions

github-actions Bot commented Jul 6, 2021

Copy link
Copy Markdown

File size impact

dist (+7,326 bytes)
Overall impact on dist files size
Diff 6.0 after merge
+7,326 329,921 337,247
Detailed impact on dist files size
File Diff 6.0 after merge Event
lib/es2015/single-spa.dev.js +1,447 55,945 57,392 changed
lib/es2015/single-spa.min.js +51 18,518 18,569 changed
lib/esm/single-spa.dev.js +1,655 59,689 61,344 changed
lib/esm/single-spa.min.js +221 20,662 20,883 changed
lib/system/single-spa.dev.js +1,805 69,528 71,333 changed
lib/system/single-spa.min.js +221 20,686 20,907 changed
lib/umd/single-spa.dev.js +1,705 63,971 65,676 changed
lib/umd/single-spa.min.js +221 20,922 21,143 changed
Impact on dist files cache

8 files in you users cache are now outdated because their content have changed.

Bytes outdated
329,921
Generated by file size impact during file-size-impact#1005454265

@internettrans

Copy link
Copy Markdown
Member Author

@cjpearson @ah3nry can you confirm that the description above, along with the code and tests, fit your needs well?

@internettrans internettrans changed the title Async cancel navigation Async navigation cancelation Jul 6, 2021

@frehner frehner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor question, otherwise looks good.

Comment thread src/navigation/reroute.js
const unloadPromises = appsToUnload.map(toUnloadPromise);
if (navigationIsCanceled) {
// Change url back to old url, without triggering the normal single-spa reroute
originalReplaceState.call(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible that originalReplaceState is null in any situation here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm good catch. I think that if someone calls navigateToUrl() before calling start() or patchHistoryApi() that it would be undefined. I'll try to reproduce in a test, then fix to have it default to window.history.replaceState if originalReplaceState is not defined.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After writing the test, it didn't throw an error. The reason is that reroute() doesn't allow you to cancel navigation until you've called start(), since it short circuits when single spa isn't started. And so this code will never execute until after patchHistoryApi (which is called by start()) is executed. See my upcoming commit in this PR that adds the test.

@internettrans

Copy link
Copy Markdown
Member Author

Going to merge this for the beta release of single-spa@6. Am happy to address any other feedback in future PRs.

@internettrans
internettrans merged commit 5f9391b into 6.0 Jul 6, 2021
@internettrans
internettrans deleted the async-cancel-navigation branch July 6, 2021 18:41
@cjpearson

Copy link
Copy Markdown
Contributor

Thanks for taking this over! I started testing with the latest beta today. So far it all looks good, and the feature is working well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants