From fa153bcface44c19e3cb80832d429e39c1e24cc7 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 2 Sep 2020 04:25:19 -0500 Subject: [PATCH] Only update lookups for dev overlay if mounted (#16776) Since the error overlay could be dismissed before this is resolved we need to make sure the component is still mounted before updating the state. --- .../src/internal/container/Errors.tsx | 10 +++++++++- yarn.lock | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/react-dev-overlay/src/internal/container/Errors.tsx b/packages/react-dev-overlay/src/internal/container/Errors.tsx index 63d5e911c2d84ea..134ec1b6eecd291 100644 --- a/packages/react-dev-overlay/src/internal/container/Errors.tsx +++ b/packages/react-dev-overlay/src/internal/container/Errors.tsx @@ -151,17 +151,25 @@ export const Errors: React.FC = function Errors({ errors }) { if (nextError == null) { return } + let mounted = true + getErrorByType(nextError).then( (resolved) => { // We don't care if the desired error changed while we were resolving, // thus we're not tracking it using a ref. Once the work has been done, // we'll store it. - setLookups((m) => ({ ...m, [resolved.id]: resolved })) + if (mounted) { + setLookups((m) => ({ ...m, [resolved.id]: resolved })) + } }, () => { // TODO: handle this, though an edge case } ) + + return () => { + mounted = false + } }, [nextError]) const [isMinimized, setMinimized] = React.useState(false) diff --git a/yarn.lock b/yarn.lock index 1795f8a363a02a4..a71e253cb2e98e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7579,10 +7579,10 @@ finalhandler@~1.1.2: statuses "~1.5.0" unpipe "~1.0.0" -finally-polyfill@0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/finally-polyfill/-/finally-polyfill-0.2.0.tgz#1b34c6e555a6c1603d2ae046e2e176d08687bfdb" - integrity sha512-3w46w5Vo4TRtk5jrLT3c8ITGxnPJhMAg3Ogbj4nmgL6thNep9+UgBgk+IRVmRpZDbwNkR7tyGsE3S3J4Qt2zVw== +finally-polyfill@0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/finally-polyfill/-/finally-polyfill-0.1.0.tgz#2a17b16581d9477db16a703c7b79a898ac0b7d50" + integrity sha512-J1LEcZ5VXe1l3sEO+S//WqL5wcJ/ep7QeKJA6HhNZrcEEFj0eyC8IW3DEZhxySI2bx3r85dwAXz+vYPGuHx5UA== find-cache-dir@3.3.1, find-cache-dir@^3.0.0, find-cache-dir@^3.3.1: version "3.3.1"