Skip to content

fix: preserve caret position in controlled custom fields#1647

Open
rinormhi wants to merge 1 commit into
puckeditor:mainfrom
rinormhi:1642-custom-field-cursor
Open

fix: preserve caret position in controlled custom fields#1647
rinormhi wants to merge 1 commit into
puckeditor:mainfrom
rinormhi:1642-custom-field-cursor

Conversation

@rinormhi
Copy link
Copy Markdown

Closes #1642

Description

This PR fixes a bug in Puck where controlled custom input fields would move the caret to the end on every keystroke while editing existing text.

The root cause was that custom fields read from the local field store, but their value was only reflected back after the async resolveComponentData -> replace roundtrip completed. For controlled inputs, that delayed sync was enough to break normal browser caret preservation.

This change keeps the existing update flow intact, but synchronizes the local field store immediately for custom and override-backed field types so controlled inputs can be edited in place as expected.

Changes made

  • Updated AutoField to synchronously mirror changes for custom field types into the local field store before forwarding onChange.
  • Applied the same local sync behavior to override-backed field types, since they use the same value path.
  • Added a regression test covering controlled custom field updates.

How to test

  • Create a custom field that renders a controlled <input>:
const MyTextField = ({ id, value, onChange }) => {
  return (
    <input
      id={id}
      value={value ?? ""}
      onChange={(e) => onChange(e.target.value)}
    />
  );
};

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 17, 2026

@rinormhi is attempting to deploy a commit to the Puck Team on Vercel.

A member of the Team first needs to authorize it.

@rinormhi rinormhi marked this pull request as ready for review April 20, 2026 09:31
@chrisvxd chrisvxd requested a review from FedericoBonel May 19, 2026 13:36
@vercel
Copy link
Copy Markdown

vercel Bot commented May 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
puck-demo Ready Ready Preview, Comment May 19, 2026 2:45pm

Request Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cursor jumps to end in controlled custom input fields

1 participant