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

Async navigation cancelation #826

Merged
merged 7 commits into from
Jul 6, 2021
Merged

Async navigation cancelation #826

merged 7 commits into from
Jul 6, 2021

Conversation

joeldenning
Copy link
Member

@joeldenning joeldenning commented Jul 6, 2021

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.

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

github-actions bot commented Jul 6, 2021

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

@joeldenning
Copy link
Member Author

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

@joeldenning joeldenning changed the title Async cancel navigation Async navigation cancelation Jul 6, 2021
Copy link
Member

@frehner frehner left a comment

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.

const unloadPromises = appsToUnload.map(toUnloadPromise);
if (navigationIsCanceled) {
// Change url back to old url, without triggering the normal single-spa reroute
originalReplaceState.call(
Copy link
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
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
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.

@joeldenning
Copy link
Member Author

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

@joeldenning joeldenning merged commit 5f9391b into 6.0 Jul 6, 2021
@joeldenning joeldenning deleted the async-cancel-navigation branch July 6, 2021 18:41
@cjpearson
Copy link
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