From 50f5002b71bdc357b3fd3fd0fb55c5d74dccebad Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 21 Mar 2019 14:43:31 +0100 Subject: [PATCH 1/3] Unmount component when closing --- packages/instant/src/index.umd.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/instant/src/index.umd.ts b/packages/instant/src/index.umd.ts index 30f33acdf8..89a20827c1 100644 --- a/packages/instant/src/index.umd.ts +++ b/packages/instant/src/index.umd.ts @@ -65,21 +65,34 @@ const validateInstantRenderConfig = (config: ZeroExInstantConfig, selector: stri assert.isString('selector', selector); }; +let injectedDiv: HTMLDivElement | undefined; +let parentElement: Element | undefined; +export const unrender = () => { + if (!injectedDiv) { + return; + } + + ReactDOM.unmountComponentAtNode(injectedDiv); + if (parentElement) { + parentElement.removeChild(injectedDiv); + } +}; + // Render instant and return a callback that allows you to remove it from the DOM. const renderInstant = (config: ZeroExInstantConfig, selector: string) => { const appendToIfExists = document.querySelector(selector); assert.assert(!_.isNull(appendToIfExists), `Could not find div with selector: ${selector}`); - const appendTo = appendToIfExists as Element; - const injectedDiv = document.createElement('div'); + parentElement = appendToIfExists as Element; + injectedDiv = document.createElement('div'); injectedDiv.setAttribute('id', INJECTED_DIV_ID); injectedDiv.setAttribute('class', INJECTED_DIV_CLASS); - appendTo.appendChild(injectedDiv); + parentElement.appendChild(injectedDiv); const closeInstant = () => { analytics.trackInstantClosed(); if (!_.isUndefined(config.onClose)) { config.onClose(); } - appendTo.removeChild(injectedDiv); + unrender(); }; const instantOverlayProps = { ...config, From 6b8e40fdc92cc7cf3a58e323a52572bda098f1c7 Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 22 Mar 2019 15:02:12 -0700 Subject: [PATCH 2/3] Make unrender idempotent --- packages/instant/src/index.umd.ts | 2 +- yarn.lock | 79 ++++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/packages/instant/src/index.umd.ts b/packages/instant/src/index.umd.ts index 89a20827c1..099544a085 100644 --- a/packages/instant/src/index.umd.ts +++ b/packages/instant/src/index.umd.ts @@ -73,7 +73,7 @@ export const unrender = () => { } ReactDOM.unmountComponentAtNode(injectedDiv); - if (parentElement) { + if (parentElement && parentElement.contains(injectedDiv)) { parentElement.removeChild(injectedDiv); } }; diff --git a/yarn.lock b/yarn.lock index 84e8cfaf81..3b3cb836f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -489,6 +489,23 @@ ethers "~4.0.4" lodash "^4.17.11" +"@0x/contracts-asset-proxy@^1.0.2": + version "1.0.9" + resolved "https://registry.npmjs.org/@0x/contracts-asset-proxy/-/contracts-asset-proxy-1.0.9.tgz#3a48e64b93ddc642834bde1bd09cdd84ca688a2b" + integrity sha512-AnKE0eDejl3G4xRzwOa2S2usiAoRvyV3lU/sOhwkG53KC6RHQGu9g50zcLHMHmTl9I088eEa423QwbeBxgmtcQ== + dependencies: + "@0x/base-contract" "^5.0.2" + "@0x/contracts-erc20" "^1.0.9" + "@0x/contracts-erc721" "^1.0.9" + "@0x/contracts-utils" "2.0.1" + "@0x/order-utils" "^7.0.2" + "@0x/types" "^2.1.1" + "@0x/typescript-typings" "^4.1.0" + "@0x/utils" "^4.2.2" + "@0x/web3-wrapper" "^6.0.2" + ethereum-types "^2.1.0" + lodash "^4.17.11" + "@0x/contracts-erc20@1.0.8": version "1.0.8" resolved "https://registry.npmjs.org/@0x/contracts-erc20/-/contracts-erc20-1.0.8.tgz#882f3acf1a44148800d9bef692aa377627df9ace" @@ -503,6 +520,21 @@ ethereum-types "^2.1.0" lodash "^4.17.11" +"@0x/contracts-erc20@^1.0.2", "@0x/contracts-erc20@^1.0.9": + version "1.0.9" + resolved "https://registry.npmjs.org/@0x/contracts-erc20/-/contracts-erc20-1.0.9.tgz#366ce8222dcae5ade0ea7ca95332416a080f6abf" + integrity sha512-CJwEWrGf0tvpnraEW+TPTjpMcwj9yDem1xVbER0qV49RRZupasVIcQmaZi4ZUpZqo4X67ZOx8uijgLXFDB9NDw== + dependencies: + "@0x/base-contract" "^5.0.2" + "@0x/contracts-exchange-libs" "1.0.2" + "@0x/contracts-utils" "2.0.1" + "@0x/types" "^2.1.1" + "@0x/typescript-typings" "^4.1.0" + "@0x/utils" "^4.2.2" + "@0x/web3-wrapper" "^6.0.2" + ethereum-types "^2.1.0" + lodash "^4.17.11" + "@0x/contracts-erc721@1.0.8": version "1.0.8" resolved "https://registry.npmjs.org/@0x/contracts-erc721/-/contracts-erc721-1.0.8.tgz#d3746c26eec57662654557121601b5bb81085637" @@ -516,6 +548,20 @@ ethereum-types "^2.1.0" lodash "^4.17.11" +"@0x/contracts-erc721@^1.0.2", "@0x/contracts-erc721@^1.0.9": + version "1.0.9" + resolved "https://registry.npmjs.org/@0x/contracts-erc721/-/contracts-erc721-1.0.9.tgz#3991858a3bf5a80dcd6e5fd65e938f8adc3b347c" + integrity sha512-Q4T93VEUChyLAz1bNRLidCtJ2/bfU1vsbeZGQeCrmm/Lcjaqm72B44SpLAiLBdTpyTfWT5gfvK+uQr1BtXTUVQ== + dependencies: + "@0x/base-contract" "^5.0.2" + "@0x/contracts-utils" "2.0.1" + "@0x/types" "^2.1.1" + "@0x/typescript-typings" "^4.1.0" + "@0x/utils" "^4.2.2" + "@0x/web3-wrapper" "^6.0.2" + ethereum-types "^2.1.0" + lodash "^4.17.11" + "@0x/contracts-exchange-libs@1.0.2": version "1.0.2" resolved "https://registry.yarnpkg.com/@0x/contracts-exchange-libs/-/contracts-exchange-libs-1.0.2.tgz#0682c01cdb3e36100bda0ffbdf9badb5b8a01fc4" @@ -530,6 +576,21 @@ ethereum-types "^2.0.0" lodash "^4.17.5" +"@0x/contracts-exchange-libs@^1.0.2": + version "1.1.3" + resolved "https://registry.npmjs.org/@0x/contracts-exchange-libs/-/contracts-exchange-libs-1.1.3.tgz#dc9429e9c5fc750e9f5006e5ad53ebd7aa577c28" + integrity sha512-M2kAMN6SO78sMyCuJLjen10CqoUNkeCFD2T8MYMpMcWWWFXTlyyeJgPllZf/ySlXSBziyJUcCRZjdwbZfF7AYQ== + dependencies: + "@0x/base-contract" "^5.0.2" + "@0x/contracts-utils" "^2.0.8" + "@0x/order-utils" "^7.0.2" + "@0x/types" "^2.1.1" + "@0x/typescript-typings" "^4.1.0" + "@0x/utils" "^4.2.2" + "@0x/web3-wrapper" "^6.0.2" + ethereum-types "^2.1.0" + lodash "^4.17.11" + "@0x/contracts-exchange@1.0.2": version "1.0.2" resolved "https://registry.yarnpkg.com/@0x/contracts-exchange/-/contracts-exchange-1.0.2.tgz#4c02378b26a7bf6324e16a41f2851c43fed82c63" @@ -565,6 +626,22 @@ ethereumjs-util "^5.1.1" lodash "^4.17.5" +"@0x/contracts-utils@^2.0.1", "@0x/contracts-utils@^2.0.8": + version "2.0.8" + resolved "https://registry.npmjs.org/@0x/contracts-utils/-/contracts-utils-2.0.8.tgz#b6a3775296e04c7ca9ebea7eae56fda48a43239d" + integrity sha512-5I1wq4ImjsIgjBNDl5F6qwJMDc6sm52vVGIxz+v9N6hUcJwaxa/SYeZ4EA5BpFdHK73xtvNe4CeRK2+g9Pt5UA== + dependencies: + "@0x/base-contract" "^5.0.2" + "@0x/order-utils" "^7.0.2" + "@0x/types" "^2.1.1" + "@0x/typescript-typings" "^4.1.0" + "@0x/utils" "^4.2.2" + "@0x/web3-wrapper" "^6.0.2" + bn.js "^4.11.8" + ethereum-types "^2.1.0" + ethereumjs-util "^5.1.1" + lodash "^4.17.11" + "@0x/order-utils@^5.0.0": version "5.0.0" resolved "https://registry.yarnpkg.com/@0x/order-utils/-/order-utils-5.0.0.tgz#7f43e0310ace31738895881501c8dda9c3a3aefa" @@ -13605,8 +13682,6 @@ react-highlight@0xproject/react-highlight#react-peer-deps: dependencies: highlight.js "^9.11.0" highlightjs-solidity "^1.0.5" - react "^16.5.2" - react-dom "^16.5.2" react-hot-loader@^4.3.3: version "4.3.4" From c481e4267327f9f9e81a68fa91845f351ae2cb91 Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 22 Mar 2019 16:21:02 -0700 Subject: [PATCH 3/3] Reset yarn.lock --- yarn.lock | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/yarn.lock b/yarn.lock index 3d8e89ec47..1928b64de2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13620,16 +13620,6 @@ react-dom@^16.3.2: object-assign "^4.1.1" prop-types "^15.6.0" -react-dom@^16.4.2: - version "16.8.5" - resolved "https://registry.npmjs.org/react-dom/-/react-dom-16.8.5.tgz#b3e37d152b49e07faaa8de41fdf562be3463335e" - integrity sha512-VIEIvZLpFafsfu4kgmftP5L8j7P1f0YThfVTrANMhZUFMDOsA6e0kfR6wxw/8xxKs4NB59TZYbxNdPCDW34x4w== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - prop-types "^15.6.2" - scheduler "^0.13.5" - react-dom@^16.5.2: version "16.5.2" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.5.2.tgz#b69ee47aa20bab5327b2b9d7c1fe2a30f2cfa9d7" @@ -13687,6 +13677,8 @@ react-highlight@0xproject/react-highlight#react-peer-deps: dependencies: highlight.js "^9.11.0" highlightjs-solidity "^1.0.5" + react "^16.4.2" + react-dom "^16.4.2" react-hot-loader@^4.3.3: version "4.3.4" @@ -13931,16 +13923,6 @@ react@^16.3.2: object-assign "^4.1.1" prop-types "^15.6.0" -react@^16.4.2: - version "16.8.5" - resolved "https://registry.npmjs.org/react/-/react-16.8.5.tgz#49be3b655489d74504ad994016407e8a0445de66" - integrity sha512-daCb9TD6FZGvJ3sg8da1tRAtIuw29PbKZW++NN4wqkbEvxL+bZpaaYb4xuftW/SpXmgacf1skXl/ddX6CdOlDw== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - prop-types "^15.6.2" - scheduler "^0.13.5" - react@^16.5.2: version "16.5.2" resolved "https://registry.yarnpkg.com/react/-/react-16.5.2.tgz#19f6b444ed139baa45609eee6dc3d318b3895d42" @@ -14812,14 +14794,6 @@ schedule@^0.5.0: dependencies: object-assign "^4.1.1" -scheduler@^0.13.5: - version "0.13.5" - resolved "https://registry.npmjs.org/scheduler/-/scheduler-0.13.5.tgz#b7226625167041298af3b98088a9dbbf6d7733a8" - integrity sha512-K98vjkQX9OIt/riLhp6F+XtDPtMQhqNcf045vsh+pcuvHq+PHy1xCrH3pq1P40m6yR46lpVvVhKdEOtnimuUJw== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - schema-utils@^0.4.4: version "0.4.7" resolved "https://registry.npmjs.org/schema-utils/-/schema-utils-0.4.7.tgz#ba74f597d2be2ea880131746ee17d0a093c68187"