Skip to content

Commit

Permalink
🐛 manual invoke single-spa start function for parcels and set urlRero…
Browse files Browse the repository at this point in the history
…uteOnly true as default (#1414)
  • Loading branch information
kuitos authored Apr 26, 2021
1 parent c759a94 commit cb67009
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@babel/runtime": "^7.10.5",
"import-html-entry": "^1.9.0",
"lodash": "^4.17.11",
"single-spa": "5.8.1",
"single-spa": "^5.9.2",
"tslib": "^1.10.0"
},
"devDependencies": {
Expand Down
21 changes: 20 additions & 1 deletion src/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ let microApps: Array<RegistrableApp<Record<string, unknown>>> = [];

// eslint-disable-next-line import/no-mutable-exports
export let frameworkConfiguration: FrameworkConfiguration = {};

let started = false;
const defaultUrlRerouteOnly = true;

const frameworkStartedDefer = new Deferred<void>();

export function registerMicroApps<T extends ObjectType>(
Expand Down Expand Up @@ -111,12 +115,26 @@ export function loadMicroApp<T extends ObjectType>(
return (await parcelConfigObjectGetterPromise)(container);
};

if (!started) {
// We need to invoke start method of single-spa as the popstate event should be dispatched while the main app calling pushState/replaceState automatically,
// but in single-spa it will check the start status before it dispatch popstate
// see https://github.com/single-spa/single-spa/blob/f28b5963be1484583a072c8145ac0b5a28d91235/src/navigation/navigation-events.js#L101
// ref https://github.com/umijs/qiankun/pull/1071
startSingleSpa({ urlRerouteOnly: frameworkConfiguration.urlRerouteOnly ?? defaultUrlRerouteOnly });
}

return mountRootParcel(memorizedLoadingFn, { domElement: document.createElement('div'), ...props });
}

export function start(opts: FrameworkConfiguration = {}) {
frameworkConfiguration = { prefetch: true, singular: true, sandbox: true, ...opts };
const { prefetch, sandbox, singular, urlRerouteOnly, ...importEntryOpts } = frameworkConfiguration;
const {
prefetch,
sandbox,
singular,
urlRerouteOnly = defaultUrlRerouteOnly,
...importEntryOpts
} = frameworkConfiguration;

if (prefetch) {
doPrefetchStrategy(microApps, prefetch, importEntryOpts);
Expand All @@ -135,6 +153,7 @@ export function start(opts: FrameworkConfiguration = {}) {
}

startSingleSpa({ urlRerouteOnly });
started = true;

frameworkStartedDefer.resolve();
}

1 comment on commit cb67009

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for qiankun ready!

✅ Preview
https://qiankun-3gvg12phr-umijs.vercel.app

Built with commit cb67009.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.