Skip to content

fix: show invalid email and url input with the default debounce - #12030

Open
burrows99 wants to merge 2 commits into
marimo-team:mainfrom
burrows99:fix/text-validation-with-debounce
Open

burrows99 wants to merge 2 commits into
marimo-team:mainfrom
burrows99:fix/text-validation-with-debounce

Conversation

@burrows99

@burrows99 burrows99 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

This pull request was authored by a coding agent.

📝 Summary

mo.ui.text(kind="email") and kind="url" outline an invalid value in red once you leave the field. With the default debounce=True that never happened: the plugin validates the value it records on blur, but in that mode it renders OnBlurredInput, which sets its own onBlur and is not given the plugin's, so the recorded value stayed at the initial one and the field always counted as valid. debounce=False and a numeric debounce were fine.

With debounce=True the committed value only changes on blur or Enter, so the plugin now validates that value directly. A one-line change in TextInputPlugin.tsx.

flowchart TD
    A[Type not-an-email into mo.ui.text kind email and leave the field] --> B{Field border}
    B -->|Before| C[Normal border]
    B -->|After| D[Red border]
Loading

Narrated recording, before then after (sound on):

text-email.mp4

Edge cases and unchanged behavior checked

Checked in the running editor (Vite dev server and marimo edit from main at a8d229e, then this branch, same notebook with mo.ui.text(kind="email"), mo.ui.text(kind="url") and mo.ui.text(kind="email", debounce=False)), and shown in the recording:

  • Before: not-an-email in the email field and not a url in the url field, then Tab: no red border on either.
  • After: both are outlined in red.
  • Edge case: correcting the address to jane@example.com and pressing Enter (no blur) clears the red border.
  • Edge case: clearing the url field and leaving it is not flagged.
  • Unchanged: a valid url (https://marimo.io) is not flagged.
  • Unchanged: the debounce=False email field still flags nope after leaving it.

Covered by tests only: debounce=200.

Tests

  • vitest run src/plugins/impl/__test__/text-labels.test.tsx: new test "marks an invalid email after blur" for debounce=false, true and 200. The debounce=true case fails on main and passes on this branch; the other two pass on both.
  • vitest run src/plugins/impl/: 55 files, 845 passed (4 expected fail).
  • tsgo (frontend typecheck): clean. oxlint and oxfmt --check on the changed files: clean.
  • Not run: make check, the Python suite, e2e.

AI assistance (Claude Code) was used for this change; the bug was reproduced and the fix checked in the running editor by the agent.

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable). Not applicable: a small bug fix with no public API change.
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes.

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes. No documentation covers this behavior.
  • Tests have been added for the changes made.

🤖 Generated with Claude Code

mo.ui.text(kind="email") and kind="url" validate the value left on
blur, but with debounce=True (the default) the blurred value was never
recorded, so an invalid address never got the red border. With
debounce=True the committed value only changes on blur or Enter, so
validate it directly.
@github-actions

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@burrows99
burrows99 marked this pull request as ready for review November 24, 2026 00:40
Copilot AI balanced review requested due to automatic review settings November 24, 2026 00:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Light2Dark Light2Dark added the bug Something isn't working label Nov 24, 2026
@kirangadhave
kirangadhave requested a balanced review from Copilot November 24, 2026 04:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the email and URL validation-styling change.

No open issues 🎉

Review effort: Balanced

@Light2Dark Light2Dark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Approve with nits

const valueToValidate = valueOnBlur == null ? value : valueOnBlur;
// With debounce=true, the value only changes on blur or Enter.
const valueToValidate =
props.debounce === true ? value : (valueOnBlur ?? value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Automated comment by Shahmir's Code Review agent running Claude Sonnet 5.5 on Claude Code

?? value fallback is unreachable

valueOnBlur is a string (useState(props.value)) and is never nullish, so ?? value never runs. The old == null check was equally dead, but since this line is being rewritten it could say what actually happens: props.debounce === true ? value : valueOnBlur.

// With debounce=true, the value only changes on blur or Enter.
const valueToValidate =
props.debounce === true ? value : (valueOnBlur ?? value);
const isValid = validate(props.kind, valueToValidate);

const { rerender } = render(plugin.render(props));
const control = screen.getByLabelText("Email");
const committed = plugin.render({ ...props, value: "not-an-email" });
if (debounce === false) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Automated comment by Shahmir's Code Review agent running Claude Sonnet 5.5 on Claude Code

Test branches on the mode and misses the Enter / recovery paths

The if (debounce === false) branch plus the second rerender(committed) make this harder to read than it needs to be, and only debounce=true was broken (false and 200 pass on main). Splitting the true case out would simplify it. Two cases from the PR's manual checks aren't covered: committing with Enter, and an invalid value corrected back to valid clearing the red border.

const committed = plugin.render({ ...props, value: "not-an-email" });
if (debounce === false) {
fireEvent.input(control, { target: { value: "not-an-email" } });
rerender(committed);

…ce=true

Validate the committed value directly for debounce=true (the old nullish
fallback could not run) and replace the mode-branching test with three
plain debounce=true cases: committed on blur, committed with Enter, and a
corrected value clearing the error.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants