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

Vue-Router compatibility in window with multiple routers #1031

Open
wants to merge 2 commits into
base: 5.x
Choose a base branch
from

Conversation

brunomartinspro
Copy link

Fix for issue #1030

@github-actions
Copy link

github-actions bot commented Aug 19, 2022

File size impact

dist (+1,490 bytes)
Overall impact on dist files size
Diff master after merge
+1,490 326,560 328,050
Detailed impact on dist files size
File Diff master after merge Event
lib/es2015/single-spa.dev.js +256 55,303 55,559 changed
lib/es2015/single-spa.min.js +113 18,398 18,511 changed
lib/esm/single-spa.dev.js +256 58,987 59,243 changed
lib/esm/single-spa.min.js +107 20,542 20,649 changed
lib/system/single-spa.dev.js +280 68,739 69,019 changed
lib/system/single-spa.min.js +107 20,569 20,676 changed
lib/umd/single-spa.dev.js +264 63,219 63,483 changed
lib/umd/single-spa.min.js +107 20,803 20,910 changed
Impact on dist files cache

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

Bytes outdated
326,560
Generated by file size impact during file-size-impact#2918016771

@brunomartinspro brunomartinspro changed the title Vue-Router compatibility in window for multiple mfes Vue-Router compatibility in window with multiple routers Aug 19, 2022
Copy link
Member

@joeldenning joeldenning left a comment

Choose a reason for hiding this comment

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

Before merging this, tests would be necessary. I am not sure if single-spa's patched updateState function should enter into the world of supporting every framework router's idiosyncrasies. My preferred solution would be to get vue router to not be so picky about other things changing history.state, but am open to discussing this if the Vue team insists that nothing else should be allowed to call history.replaceState() besides their code.

@@ -94,6 +94,12 @@ function urlReroute() {
function patchedUpdateState(updateState, methodName) {
return function () {
const urlBefore = window.location.href;

// issues/1030 - Vue requires 'current' to be set at all times
if (arguments && arguments[0] && !arguments[0]?.current) {
Copy link
Member

Choose a reason for hiding this comment

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

I prefer not using the arguments keyword. Also, the optional chaining on this line seems unnecessary since there's already a check for whether arguments[0] is truthy.

I'd prefer something like this:

return function (state) {
  if (state && !state.current) {
    state.current = "";
  }  
}

Copy link
Author

Choose a reason for hiding this comment

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

Hi @joeldenning ,
i tried solving this on the vue-router side but there seemed to be no flexibility on their end to fix it vuejs/router#1502

Regarding the arguments, where do i get the "state" object?
The arguments seem to be directly applied to the window.history.pushState or window.history.replaceState on the code:
const result = updateState.apply(this, arguments);

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.

None yet

2 participants