Skip to content

Exiting a @change handler undoes changes made in the handler #111

@ssilverman

Description

@ssilverman

Observed (with Javascript tracing in Safari on a Mac):

  1. Change a text input value to something I know is invalid (in my case, it's one character too long, specified with both a pattern attribute and checked in a "check()" function)
  2. @change event gets fired
  3. The event handler first sets the border colour to empty (e.target.style.borderColor = "")
  4. Then a check() function is called (still inside the change event handler)
  5. The function correctly identifies that there's a problem with the text and sets the element's style.borderColor to "red"
  6. I observe this change while stepping through the code — the border turns red
  7. The function exits — the border stays red, as desired
  8. Tracing goes to the element itself, and when I hit "step over", the input element goes back to having no border colour

I run through these steps again, and instead of "step over", I hit "step into" and trace the "undo my changes line" (in an un-minified arrow.js, (Source: https://cdn.skypack.dev/pin/@arrow-js/[email protected]/mode=imports/optimized/@arrow-js/core.js)):

function setNode(value, p) {
  const isUpdate = typeof p === "function";
  const partial = isUpdate ? p : createPartial();
  Array.isArray(value) ? value.forEach((item) => measure("partialAdd", () => partial.add(item))) : partial.add(value);
  if (isUpdate)
    partial._up();  // <-- HERE

The code is getting a little complex for me, but I know that when that partial._up(); line is processed, the element has all my changes reverted.

Note that I also tried setting the className property when there's an error to "has-error" (accompanied by an input.has-error { border-color: red } style in a <style> section), and also tried adding to classList, but all three approaches (setting style.borderColor, setting className, and doing classList.add("has-error")) lead to the border colour being changed to red, followed by reverting to non-red when the change handler exits.

I tried making a small representative example, but that example doesn't fail, so it could either be my logic, or the error only happens when there's a much larger DOM tree. If you like, I'm happy to screen share and prove that exiting a change handler undoes my changes when inside the ArrowJS code.

Thanks again for a wonderful library! It's helping me get started with modern web page design.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions