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

Debounce emitted events in React #1864

Merged
merged 3 commits into from
Jan 13, 2022

Conversation

sdirix
Copy link
Member

@sdirix sdirix commented Jan 4, 2022

There are some use cases in which a large amount of independent changes are
performed in an extremely low amount of time, potentially leading to data
loss or endless rerendering loops when using the React bindings.

An example for such a use case is Chrome auto-fill which can cause JSON Forms
to emit multiple change events before the parent component is rerendered. If
the parent component feeds the emitted data back to JSON Forms then it will
hand over not the latest data, but the previouslys emitted data first. JSON
Forms recognizes that this is not the very recent data and will validate,
rerender and emit a change event again, leading to the problematic behavior.

To handle these edge cases in which many change events are sent in an
extremely short amount of time we debounce them over a short amount of time.
We debounce the emitted events instead of the incoming data as we don't know
anything about the amount of work performed (and therefore time passed) on the
emitted data.

Adds an event cache to the React integration for emitted events.
Skips emitting events which were already emitted very recently.

This fixes an endless rendering loop issue in cases where the user
dispatched many change events in a small amount of time, e.g. via
Browser autofill features. When that happened and the user also
fed back the emitted data to JSON Forms, the user could end up in
an endless update cycle of type A -> B -> A -> B... . This is now
avoided.
@sdirix sdirix linked an issue Jan 4, 2022 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Jan 4, 2022

Coverage Status

Coverage remained the same at 84.242% when pulling a9455d1 on sdirix:react-unique-events into e9400b6 on eclipsesource:master.

@sdirix sdirix changed the title Only emit unique events in React Debounce emitted events in React Jan 13, 2022
There are some use cases in which a large amount of independent changes are
performed in an extremely low amount of time, potentially leading to data
loss or endless rerendering loops when using the React bindings.

An example for such a use case is Chrome auto-fill which can cause JSON Forms
to emit multiple change events before the parent component is rerendered. If
the parent component feeds the emitted data back to JSON Forms then it will
hand over not the latest data, but the previouslys emitted data first. JSON
Forms recognizes that this is not the very recent data and will validate,
rerender and emit a change event again, leading to the problematic behavior.

To handle these edge cases in which many change events are sent in an
extremely short amount of time we debounce them over a short amount of time.
We debounce the emitted events instead of the incoming data as we don't know
anything about the amount of work performed (and therefore time passed) on the
emitted data.
@sdirix sdirix merged commit 95018ca into eclipsesource:master Jan 13, 2022
@sdirix sdirix deleted the react-unique-events branch January 13, 2022 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infinite loop caused by Address Autofill in Chrome
3 participants