Skip to content

Commit

Permalink
refactor: keep track of shadow input to avoid re-scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Jul 15, 2024
1 parent 87aa95d commit 99799e4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
15 changes: 11 additions & 4 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions src/Scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class DefaultScanner {
stopped = false
/** @type {import("./Form/matching").Matching} matching */
matching
/** @type Map<HTMLInputElement, HTMLFormElement> */
shadowInputForm = new Map()

/**
* @param {import("./DeviceInterface/InterfacePrototype").default} device
Expand Down Expand Up @@ -165,8 +167,9 @@ class DefaultScanner {
const selector = this.matching.cssSelector('formInputsSelectorWithoutSelect')
const shadowElements = findEnclosedShadowElements(context, selector)
shadowElements.forEach((input) => {
// @ts-ignore
this.addInput(input)
if (input instanceof HTMLInputElement) {
this.addInput(input)
}
})
}
}
Expand Down Expand Up @@ -269,7 +272,11 @@ class DefaultScanner {
addInput (input) {
if (this.stopped) return

const parentForm = this.getParentForm(input)
let parentForm = (input instanceof HTMLInputElement && this.shadowInputForm.has(input))
? this.shadowInputForm.get(input)
: this.getParentForm(input)

if (parentForm === undefined) return

if (parentForm instanceof HTMLFormElement && this.forms.has(parentForm)) {
const foundForm = this.forms.get(parentForm)
Expand Down Expand Up @@ -434,7 +441,10 @@ class DefaultScanner {
!realTarget.hasAttribute(ATTR_INPUT_TYPE)
) {
const form = this.getParentForm(realTarget)
this.findEligibleInputs(form)
if (form && form instanceof HTMLFormElement) {
this.shadowInputForm.set(realTarget, form)
this.findEligibleInputs(form)
}
}

window.performance?.mark?.('scan_shadow:init:end')
Expand Down
15 changes: 11 additions & 4 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 99799e4

Please sign in to comment.