LearnNewsExamplesConnect
Frontmatter
assigneesneo-gemini-maryam
createdAtNov 20, 2026, 3:50 AM
updatedAtNov 20, 2026, 3:49 PM
githubUrlhttps://github.com/neomjs/neo/issues/21555
authorneo-gemini-maryam
commentsCount1
parentIssue21329
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtNov 20, 2026, 3:49 PM

PrefixField reorders fast keystrokes and leaves rapid multi-field fills unmasked

neo-gemini-maryam
neo-gemini-maryam commented on Nov 20, 2026, 3:50 AM

Context

Promoted from @neo-opus-ada's defect-note (MESSAGE:671786e5, observed on examples/fieldWithPrefix at dev 53ed5d36e5 while capturing covers for #21551 under #21329):

  • Typing into a Neo.plugin.PrefixField-masked TextField faster than an App-Worker round trip (pressSequentially with 0 ms delay or fast typing) reorders and mangles characters — e.g. date 201120260930 becomes 02/60/9302 01:1m, and MAC ABCDEF becomes DE:FA:BX:XX:XX:XX.
  • Filling five masked fields back-to-back without artificial ~700 ms pauses (fill() / paste / autofill) leaves fields 2–4 raw/unmasked and the Credit Card field empty.
  • Also blocks reliable Playwright typing verification on contributor GFI #21502 (AC-1: typing 001A2B3C4D5E into the MAC Address field).

The Problem

Neo.plugin.PrefixField (src/plugin/PrefixField.mjs:127-136, 207-226) currently performs live DOM input masking and caret placement asynchronously from the App Worker:

  1. Cross-thread VDOM/caret clobber on fast keystrokes: PrefixField listens to selectionchange, keydown, focusin, and focusout in the App Worker, sets el.value = clean(value).join('') (triggering an async VDOM delta), and calls Neo.main.DomAccess.selectNode(...) (an async RMA call) while setting me.ignoreSelection = true and immediately me.ignoreSelection = false synchronously before the RMA even crosses to Main (:220-223). Any keystroke arriving on the Main Thread <input> before the worker VDOM delta + selectNode return gets overwritten or inserted at a stale caret index.
  2. Missed fill() / paste events without selectionchange: src/plugin/PrefixField.mjs:131-136 never listens to input at all — it relies on document's selectionchange, which browsers coalesce per frame/activeElement and do not emit per field across rapid programmatic fill() or autofill sequences.
  3. Orphan single-instance src/main/addon/PrefixField.mjs: An experimental Neo.main.addon.PrefixField (src/main/addon/PrefixField.mjs:1-139) already ships as a lazy Main-Thread addon chunk in every build, but is completely unwired, stores single-element state (this.el, this.pattern, this.back) on the singleton instead of per-element in a Map (breaking multi-field views like examples/fieldWithPrefix's 5 inputs), listens to keypress (which never fires for Backspace), and leaves console.log in format() (:126).
  4. RegExp flag loss in clean(): new RegExp(this.accept || "\\d", "g") (src/plugin/PrefixField.mjs:193) strips flags like 'i' when accept is a case-insensitive RegExp (e.g. /[0-9a-f]/i).

The Architectural Reality

  • Design authority: examples/fieldWithPrefix/MainContainer.mjs:15 ("Type into a field: the mask fills its slots as you go and refuses characters it does not accept") and src/form/field/Text.mjs:1550-1557 ("The user's input has changed the real DOM on the Main Thread. We must manually update our 'last known state' (this.vnode) to match this reality before the next diffing cycle runs. This prevents the framework from sending a redundant delta update that could overwrite the user's input or cause cursor jumps.").
  • src/main/DomEvents.mjs:11-15, 565-581, 642-651: DomEvents delegates input, keydown, focusin, and focusout in bubble phase on document.body, and onChange(event) reads value: target.value. Therefore, direct target-phase listeners on the <input> element inside Neo.main.addon.PrefixField execute synchronously on the Main Thread before DomEvents#onChange reads target.value:
    • On input: <input>.value and setSelectionRange(i, j) settle synchronously on Main before the next keystroke AND before DomEvents#onChange forwards {type: 'input', value: masked} to TextField#onInputValueChange, which updates inputVNode.attributes.value and reportedInputValue without emitting a clobbering worker-to-main value delta.
    • On focusin / focusout: when focus shows the empty mask template or blur clears an unfilled template (el.value === pattern), dispatching a bubbling input event from <input> (guarded against re-entry) synchronizes TextField in FIFO order before focusout reaches TextField#onFocusLeave (resolving to TextField#emptyValue).

The Fix

  1. Promote Neo.main.addon.PrefixField (src/main/addon/PrefixField.mjs) into the multi-instance Main-Thread mask controller:
    • Key per-input state in this.fields = new Map() (id -> {el, accept, pattern, slots, prev, first, back, formatting, listeners}), removing singleton this.el state and console.log.
    • Expose remote.app: register, setConfigs, unregister (matching test/playwright/setup.mjs:58-62).
    • Handle keydown (Backspace tracking), input (synchronous clean + setSelectionRange before DomEvents#onChange), focusin (template display + caret at first unfilled slot), click (snap collapsed caret into valid slot range when clicking outside filled slots while preserving range selections), and focusout (clear untouched pattern to '' before DomEvents#onFocusOut).
    • Preserve RegExp flags ('i', 'u') alongside 'g' when compiling accept.
  2. Wire Neo.plugin.PrefixField (src/plugin/PrefixField.mjs) to Neo.main.addon.PrefixField:
    • Remove the async App-Worker selectionchange / keydown / focusin / focusout DOM listeners and broken synchronous ignoreSelection toggle around DomAccess.selectNode.
    • Load Neo.currentWorker.getAddon('PrefixField', owner.windowId) on onOwnerMounted() (supporting remounts per Neo.plugin.Base and destroy() cleanup via unregister), forwarding serialized {id: owner.getInputElId(), acceptSource, acceptFlags, pattern, slots, windowId} on register and setConfigs.
    • Retain clean(input) (with RegExp flag preservation) and wrap owner.beforeSetValue (restored in destroy()) in the App Worker so Node unit specs and programmatic field.value = ... mutations format atomically without DOM round-trips.
  3. Add Playwright unit + real-browser component coverage:
    • test/playwright/unit/plugin/PrefixField.spec.mjs: unit coverage for clean(), RegExp flag preservation (/[0-9a-f]/i), programmatic TextField value formatting, and register/setConfigs/unregister lifecycle.
    • test/playwright/component/form/field/PrefixField.spec.mjs: real OMT browser test mounting five masked TextFields and verifying zero-delay pressSequentially('201120260930') ('20/11/2026 09:30'), zero-delay MAC keystrokes, five consecutive pause-free fill() calls across all five fieldWithPrefix masks, Backspace across separators, untouched focus/blur clearing, and live runtime config updates.

Contract Ledger

Target Surface Source of Authority Proposed Behavior Fallback / Edge Case Docs Evidence
Neo.plugin.PrefixField (accept_, pattern_, slots_, clean()) (src/plugin/PrefixField.mjs:53-62, 191-201) examples/fieldWithPrefix/MainContainer.mjs:15, 22-32 & #21502 Out of Scope Preserves public config names (accept, pattern, slots, inputCls, labelCls, ownerCls); registers/updates/unregisters Neo.main.addon.PrefixField per owner.windowId (register, setConfigs, unregister) and preserves RegExp flags (e.g. 'i') when matching accept. Unmounted/unit-test TextField formats programmatic non-empty value in App Worker via beforeSetValue without calling Main addon (''/null resolves to TextField#emptyValue); null accept defaults to /\d/g; null slots defaults to '_'. Yes (JSDoc) test/playwright/unit/plugin/PrefixField.spec.mjs
Neo.main.addon.PrefixField (register, setConfigs, unregister) (src/main/addon/PrefixField.mjs:21-27) src/form/field/Text.mjs:1550-1557 & src/main/DomEvents.mjs:565-581 Manages per-input state in Map by id; stamps data-neo-prefix-ready="true" while registered; formats <input>.value and setSelectionRange synchronously on Main during input, focusin, click, and focusout before bubble-phase DomEvents reads target.value. Missing DOM node on register returns false without throwing; setConfigs on unregistered id delegates to register; re-registering existing id detaches prior listeners first; drag/range selection on click is preserved. Yes (JSDoc) test/playwright/component/form/field/PrefixField.spec.mjs

Acceptance Criteria

  • AC-1: Zero-delay back-to-back keystrokes (pressSequentially with delay: 0) in a real browser OMT TextField with Neo.plugin.PrefixField preserve exact character order and slot separators (e.g. '201120260930' in dd/mm/yyyy hh:mm → '20/11/2026 09:30'; 'ABCDEF123456' in hex MAC mask → 'AB:CD:EF:12:34:56').
  • AC-2: Consecutive pause-free fill() calls across five masked TextFields in one container mask every field and synchronize TextField#value in the App Worker without dropping or leaving raw values.
  • AC-3: Focusing an empty masked field displays pattern at the first slot, blurring without accepted input clears <input>.value to '' and TextField#value to emptyValue (null), Backspace steps back across literal separators, and runtime pattern/slots/accept config updates re-sync the live mask.
  • AC-4: npm run test-unit -- test/playwright/unit/plugin/PrefixField.spec.mjs and npm run test-components -- test/playwright/component/form/field/PrefixField.spec.mjs pass (and fail on dev before the fix).

Out of Scope

  • Changing examples/fieldWithPrefix/MainContainer.mjs phone-width sizing or MAC label/config (#21502, reserved for external contributor pickup).
  • Modifying apps/portal/resources/data/examples.json (#21552).

Avoided Traps

  • Keeping masking in App-Worker selectionchange with await DomAccess.selectNode: Even awaiting the RMA leaves a full worker round-trip gap during which fast native keystrokes land at unformatted indices on Main.
  • Singleton this.el field state in Neo.main.addon.PrefixField: Clobbers earlier masked fields whenever a page mounts more than one PrefixField (examples/fieldWithPrefix mounts five).
  • Mutating examples/fieldWithPrefix/MainContainer.mjs: Collides with open contributor GFI #21502.

Related

Parent #21329 · #21140 · unblocks #21502 (AC-1 fast typing) · surfaced while capturing #21551 (#21552).

Ownership: self-assigned maintainer lane (@neo-gemini-maryam); curated good first issue / help wanted omitted because fixing an OMT cross-worker DOM/VDOM input-synchronization race across src/plugin/ and src/main/addon/ requires maintainer engine context ahead of the Engine 14 cut and unblocks contributor GFI #21502.

Decision Record impact: none.

Live latest-open + closed sweep: checked latest 20 open (#21553..#21359, 60 open — red band, filed under owning epic #21329 which has 19 subs) + open and closed search (PrefixField, fieldWithPrefix, "input mask", Out of Scope and Avoided Traps read on #21337, #21502, #21329) at 2026-11-20T02:47Z; no equivalent or prior exclusion found. A2A in-flight claim sweep: latest 30 messages across all read-states (through 2026-11-20T02:45:26Z), promoted from @neo-opus-ada's defect-note (MESSAGE:671786e5), zero competing claims on PrefixField. MC sweep: "fieldWithPrefix PrefixField back-to-back key presses reorder characters unmasked fill", 5 results + ask_knowledge_base (ticket), no prior decision found. Own-assignment sweep: 3 open (#21553, #21547, #21512, all 3 in APPROVED PRs at merge gate), none overlapping.

Origin Session ID: 095892f3-027f-47aa-8092-a13ae31f72ca Retrieval Hint: "PrefixField Main thread addon input mask back-to-back keystrokes reorder characters unmasked fill race"

tobiu referenced in commit f6ed1d8 - "fix(plugin): run PrefixField input masking synchronously on Main thread (#21555) (#21556)" on Nov 20, 2026, 3:49 PM
tobiu closed this issue on Nov 20, 2026, 3:49 PM