Skip to content

fill_in races with phx-change: clear triggers patch before set_value #9

@pinetops

Description

@pinetops

Problem

fill_in calls clear() then set_value(). Both trigger phx-change on the form:

  1. clear() → empties input → phx-change fires with email: ""
  2. set_value() → types characters → phx-change fires with email: "user@test.com"

with_patch_await wraps fill_in and resolves after the FIRST patch (from clear). The test continues, click("Submit") fires before the server has processed set_value's change event. The server state still has an empty email.

Evidence

Screenshot shows the sign-in form with an empty email field after fill_in + click sequence. Intermittent under concurrent load.

Fix options

  1. fill_in should await patch after set_value, not after clear — move with_patch_await to wrap only set_value, or await twice
  2. clear should not trigger phx-change — use JS to clear without dispatching input/change events
  3. Debounce-aware fill_in — after typing, wait for the debounce period + patch before returning

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions