aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-11-17 08:33:02 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-11-17 08:33:02 +0800
commit9384c507ac29043d0d2f68bef3dde94a43282d09 (patch)
tree88e40f01786aef6674c4244bb42705e49506860f /packages/instant/src
parentac942faa258f604f4f6171759f6bcdf786317d29 (diff)
downloaddexon-sol-tools-9384c507ac29043d0d2f68bef3dde94a43282d09.tar
dexon-sol-tools-9384c507ac29043d0d2f68bef3dde94a43282d09.tar.gz
dexon-sol-tools-9384c507ac29043d0d2f68bef3dde94a43282d09.tar.bz2
dexon-sol-tools-9384c507ac29043d0d2f68bef3dde94a43282d09.tar.lz
dexon-sol-tools-9384c507ac29043d0d2f68bef3dde94a43282d09.tar.xz
dexon-sol-tools-9384c507ac29043d0d2f68bef3dde94a43282d09.tar.zst
dexon-sol-tools-9384c507ac29043d0d2f68bef3dde94a43282d09.zip
feat: add isInstantRendered check to safeguard against double renders and double removes
Diffstat (limited to 'packages/instant/src')
-rw-r--r--packages/instant/src/index.umd.ts18
1 files changed, 13 insertions, 5 deletions
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);