diff options
Diffstat (limited to 'packages/instant')
-rw-r--r-- | packages/instant/public/index.html | 4 | ||||
-rw-r--r-- | packages/instant/src/index.umd.ts | 18 |
2 files changed, 17 insertions, 5 deletions
diff --git a/packages/instant/public/index.html b/packages/instant/public/index.html index 039f8b781..557cfa3dc 100644 --- a/packages/instant/public/index.html +++ b/packages/instant/public/index.html @@ -27,6 +27,10 @@ <body> <div id="zeroExInstantContainer"></div> <script> + // Simulate history + window.history.pushState({ page: 1 }, '0x Instant'); + window.history.pushState({ page: 2 }, '0x Instant'); + window.history.pushState({ page: 3 }, '0x Instant'); const removeUndefined = (obj) => { for (let k in obj) if (obj[k] === undefined) delete obj[k]; return obj; diff --git a/packages/instant/src/index.umd.ts b/packages/instant/src/index.umd.ts index 34d893ad7..64f888e00 100644 --- a/packages/instant/src/index.umd.ts +++ b/packages/instant/src/index.umd.ts @@ -68,7 +68,9 @@ export const render = (config: ZeroExInstantConfig, selector: string = DEFAULT_Z return closeInstant; }; if (config.shouldDisablePushToHistory) { - renderInstant(); + if (!isInstantRendered()) { + renderInstant(); + } } else { // Before we render, push to history saying that instant is showing for this part of the history. window.history.pushState({ zeroExInstantShowing: true }, '0x Instant'); @@ -83,12 +85,18 @@ export const render = (config: ZeroExInstantConfig, selector: string = DEFAULT_Z prevOnPopState(e); // e.state represents the new state if (e.state && e.state.zeroExInstantShowing) { - // The user pressed fowards, so re-render instant. - removeInstant = renderInstant(); + // We have returned to a history state that expects instant to be rendered. + if (!isInstantRendered()) { + removeInstant = renderInstant(); + } } else { - // User pressed back, so close instant. - removeInstant(); + // History has changed to a different state. + if (isInstantRendered()) { + removeInstant(); + } } }; } }; + +const isInstantRendered = (): boolean => !!document.getElementById(INJECTED_DIV_ID); |