From 7e304a2624eb6ae939219fae90efdd702e81f352 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 25 Feb 2022 09:41:21 -1000 Subject: [PATCH] Prevent setting state on unmounted withOnyx components --- lib/Onyx.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Onyx.js b/lib/Onyx.js index 75a8c8bcc..38fc32bc3 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -358,6 +358,12 @@ function keyChanged(key, data) { * @param {String} key */ function sendDataToConnection(config, val, key) { + // If the mapping no longer exists then we should not send any data. + // This means our subscriber disconnected or withOnyx wrapped component unmounted. + if (!callbackToStateMapping[config.connectionID]) { + return; + } + if (config.withOnyxInstance) { config.withOnyxInstance.setWithOnyxState(config.statePropertyName, val); } else if (_.isFunction(config.callback)) { @@ -388,6 +394,7 @@ function sendDataToConnection(config, val, key) { function connect(mapping) { const connectionID = lastConnectionID++; callbackToStateMapping[connectionID] = mapping; + callbackToStateMapping[connectionID].connectionID = connectionID; if (mapping.initWithStoredValues === false) { return connectionID;