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

Fix flickering inputs on Webkit browsers #559

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

sergei-maertens
Copy link
Member

Closes open-formulieren/open-forms#3511

Some difference in the JS engine in WebKit (the browser engine behind Safari or any other browser on iOS/MacOS) vs. Gecko (Firefox) and Blink (Chromium, Edge) seems to cause a different (debounce) behaviour and or event firing/acting on events w/r to the Formio renderer.

On Webkit, the formio initialized event triggered with mismatching backend data, causing the form field inputs to be cleared and the submission to be updated, which in turn triggers the logic check again due to a change event being fired. This then leads again to a change in the formio configuration and the formio renderer re-initializing, ad infinitum. Somewhere the form data and form configuration state goes out of sync and it's incredibly hard to manage this, especially due to the large number of related issues in the past.

Since we use the formio initialized event pretty much only to form step data from earlier submissions or when navigating between steps, we avoid setting updated form data at all in formio initialized events triggered by logic evaluations. The logic evaluation itself already manages the form instance submission data, in case that the backend returns calculated/derived values, for example.

I truly hope this doesn't break anything else, but due to the lack of tests (granted, it's near impossible to test this mess) and complexity of this part of the code base, I can't say I'm very confident in this fix.

…browsers

Some difference in the JS engine in WebKit (the browser engine behind
Safari or any other browser on iOS/MacOS) vs. Gecko (Firefox) and Blink
(Chromium, Edge) seems to cause a different (debounce) behaviour and
or event firing/acting on events w/r to the Formio renderer.

On Webkit, the formio initialized event triggered with mismatching
backend data, causing the form field inputs to be cleared and the
submission to be updated, which in turn triggers the logic check again
due to a change event being fired. This then leads again to a change
in the formio configuration and the formio renderer re-initializing,
ad infinitum. Somewhere the form data and form configuration state
goes out of sync and it's incredibly hard to manage this, especially
due to the large number of related issues in the past.

Since we use the formio initialized event pretty much only to form
step data from earlier submissions or when navigating between steps,
we avoid setting updated form data at all in formio initialized events
triggered by logic evaluations. The logic evaluation itself already
manages the form instance submission data, in case that the backend
returns calculated/derived values, for example.

I truly hope this doesn't break anything else, but due to the lack
of tests (granted, it's near impossible to test this mess) and
complexity of this part of the code base, I can't say I'm very
confident in this fix.
@sergei-maertens sergei-maertens added the needs-backport Fix must be backported to stable release branch label Sep 29, 2023
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (5db3465) 70.90% compared to head (dde08a5) 70.55%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #559      +/-   ##
==========================================
- Coverage   70.90%   70.55%   -0.36%     
==========================================
  Files         207      207              
  Lines        4290     4296       +6     
  Branches     1163     1165       +2     
==========================================
- Hits         3042     3031      -11     
- Misses       1216     1233      +17     
  Partials       32       32              
Files Coverage Δ
src/components/FormStep/index.js 35.10% <100.00%> (+1.62%) ⬆️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sergei-maertens
Copy link
Member Author

Needs backporting to 1.4.x and 1.5.x - 1.3.x is React 17 based, which doesn't seem to have this bug. The React 18 upgrade doing the batching of state updates is suspected to not play nice with the formio events.

@sergei-maertens sergei-maertens merged commit bd7e2de into main Sep 29, 2023
11 of 12 checks passed
@sergei-maertens sergei-maertens deleted the issue/3511-blinking-user-input branch September 29, 2023 12:33
sergei-maertens added a commit that referenced this pull request Sep 29, 2023
…browsers

Some difference in the JS engine in WebKit (the browser engine behind
Safari or any other browser on iOS/MacOS) vs. Gecko (Firefox) and Blink
(Chromium, Edge) seems to cause a different (debounce) behaviour and
or event firing/acting on events w/r to the Formio renderer.

On Webkit, the formio initialized event triggered with mismatching
backend data, causing the form field inputs to be cleared and the
submission to be updated, which in turn triggers the logic check again
due to a change event being fired. This then leads again to a change
in the formio configuration and the formio renderer re-initializing,
ad infinitum. Somewhere the form data and form configuration state
goes out of sync and it's incredibly hard to manage this, especially
due to the large number of related issues in the past.

Since we use the formio initialized event pretty much only to form
step data from earlier submissions or when navigating between steps,
we avoid setting updated form data at all in formio initialized events
triggered by logic evaluations. The logic evaluation itself already
manages the form instance submission data, in case that the backend
returns calculated/derived values, for example.

I truly hope this doesn't break anything else, but due to the lack
of tests (granted, it's near impossible to test this mess) and
complexity of this part of the code base, I can't say I'm very
confident in this fix.

Backport-of: #559
sergei-maertens added a commit that referenced this pull request Sep 29, 2023
…browsers

Some difference in the JS engine in WebKit (the browser engine behind
Safari or any other browser on iOS/MacOS) vs. Gecko (Firefox) and Blink
(Chromium, Edge) seems to cause a different (debounce) behaviour and
or event firing/acting on events w/r to the Formio renderer.

On Webkit, the formio initialized event triggered with mismatching
backend data, causing the form field inputs to be cleared and the
submission to be updated, which in turn triggers the logic check again
due to a change event being fired. This then leads again to a change
in the formio configuration and the formio renderer re-initializing,
ad infinitum. Somewhere the form data and form configuration state
goes out of sync and it's incredibly hard to manage this, especially
due to the large number of related issues in the past.

Since we use the formio initialized event pretty much only to form
step data from earlier submissions or when navigating between steps,
we avoid setting updated form data at all in formio initialized events
triggered by logic evaluations. The logic evaluation itself already
manages the form instance submission data, in case that the backend
returns calculated/derived values, for example.

I truly hope this doesn't break anything else, but due to the lack
of tests (granted, it's near impossible to test this mess) and
complexity of this part of the code base, I can't say I'm very
confident in this fix.

Backport-of: #559
@sergei-maertens
Copy link
Member Author

Backports: e38931f, 9b68e06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-backport Fix must be backported to stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Safari: iOS + macOS: User input is blinking
2 participants