Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove optimization that was supposed to help with infinite rendering… #421

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/withOnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import utils from './utils';

// This is a list of keys that can exist on a `mapping`, but are not directly related to loading data from Onyx. When the keys of a mapping are looped over to check
// if a key has changed, it's a good idea to skip looking at these properties since they would have unexpected results.
const mappingPropertiesToIgnoreChangesTo = ['initialValue'];
const mappingPropertiesToIgnoreChangesTo = ['initialValue', 'allowStaleData'];

/**
* Returns the display name of a component
Expand Down Expand Up @@ -119,12 +119,9 @@ export default function (mapOnyxToState, shouldDelayUpdates = false) {
const onyxDataFromState = getOnyxDataFromState(this.state, mapOnyxToState);
const prevOnyxDataFromState = getOnyxDataFromState(prevState, mapOnyxToState);

// This ensures that only one property is reconnecting at a time, or else it can lead to race conditions and infinite rendering loops. No fun!
let isReconnectingToOnyx = false;

_.each(mapOnyxToState, (mapping, propName) => {
// Some properties can be ignored and also return early if the component is already reconnecting to Onyx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also update that comment that mentions the reconnecting.

if (_.includes(mappingPropertiesToIgnoreChangesTo, propName) || isReconnectingToOnyx) {
if (_.includes(mappingPropertiesToIgnoreChangesTo, propName)) {
return;
}

Expand All @@ -140,7 +137,6 @@ export default function (mapOnyxToState, shouldDelayUpdates = false) {
: Str.result(mapping.key, {...prevProps, ...prevOnyxDataFromState});
const newKey = Str.result(mapping.key, {...this.props, ...onyxDataFromState});
if (previousKey !== newKey) {
isReconnectingToOnyx = true;
Onyx.disconnect(this.activeConnectionIDs[previousKey], previousKey);
delete this.activeConnectionIDs[previousKey];
this.connectMappingToOnyx(mapping, propName, newKey);
Expand Down
Loading