-
Notifications
You must be signed in to change notification settings - Fork 11
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
Revert mutation observer for forms #396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ import {constants} from '../constants.js' | |
const { | ||
ATTR_AUTOFILL, | ||
ATTR_INPUT_TYPE, | ||
MAX_FORM_MUT_OBS_COUNT, | ||
MAX_INPUTS_PER_FORM | ||
} = constants | ||
|
||
|
@@ -77,30 +76,6 @@ class Form { | |
} | ||
}) | ||
|
||
this.mutObsCount = 0 | ||
this.mutObsConfig = { childList: true, subtree: true } | ||
this.mutObs = new MutationObserver( | ||
(records) => { | ||
const anythingRemoved = records.some(record => record.removedNodes.length > 0) | ||
if (anythingRemoved) { | ||
// Must check for inputs because a parent may be removed and not show up in record.removedNodes | ||
if ([...this.inputs.all].some(input => !input.isConnected)) { | ||
// If any known input has been removed from the DOM, reanalyze the whole form | ||
window.requestIdleCallback(() => { | ||
this.formAnalyzer = new FormAnalyzer(this.form, input, this.matching) | ||
this.recategorizeAllInputs() | ||
}) | ||
|
||
this.mutObsCount++ | ||
// If the form mutates too much, disconnect to avoid performance issues | ||
if (this.mutObsCount >= MAX_FORM_MUT_OBS_COUNT) { | ||
this.mutObs.disconnect() | ||
} | ||
} | ||
} | ||
} | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't directly related to the breakage, but I'm dropping it now before investigating things further in the next few days. |
||
// This ensures we fire the handler again if the form is changed | ||
this.addListener(form, 'input', () => { | ||
if (!this.isAutofilling) { | ||
|
@@ -110,7 +85,6 @@ class Form { | |
}) | ||
|
||
this.categorizeInputs() | ||
this.mutObs.observe(this.form, this.mutObsConfig) | ||
|
||
this.logFormInfo() | ||
|
||
|
@@ -356,7 +330,6 @@ class Form { | |
this.removeAllDecorations() | ||
this.removeTooltip() | ||
this.forgetAllInputs() | ||
this.mutObs.disconnect() | ||
this.matching.clear() | ||
this.intObs = null | ||
} | ||
|
@@ -444,13 +417,6 @@ class Form { | |
return this | ||
} | ||
|
||
// When new inputs are added after the initial scan, reanalyze the whole form | ||
if (this.initialScanComplete) { | ||
this.formAnalyzer = new FormAnalyzer(this.form, input, this.matching) | ||
this.recategorizeAllInputs() | ||
return this | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what was causing the problem. Basically, in certain edge cases the container of the field (what here we call The failsafe we built for the form-specific mutation observer wasn't running here because the trigger comes from outside (the scanner), not from the internal observer. In our browser the slowdown was limited (still massive), but on Firefox it could hang for several seconds and show the warning. |
||
|
||
// Nothing to do with 1-character fields | ||
if (input.maxLength === 1) return this | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,8 +226,13 @@ class DefaultScanner { | |
const parentForm = this.getParentForm(input) | ||
|
||
if (parentForm instanceof HTMLFormElement && this.forms.has(parentForm)) { | ||
// We've met the form, add the input | ||
this.forms.get(parentForm)?.addInput(input) | ||
const foundForm = this.forms.get(parentForm) | ||
// We've met the form, add the input provided it's below the max input limit | ||
if (foundForm && foundForm.inputs.all.size < MAX_INPUTS_PER_FORM) { | ||
foundForm.addInput(input) | ||
} else { | ||
this.stopScanner('The form has too many inputs, destroying.') | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've moved this check in the scanner as well for added security. I have a few follow up tasks in Asana to try and understand this flow better and see how we can make it more resilient to breakage. |
||
return | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just switching the test off for now.