visual-editing: "Edit" on a block inside a rich text field focuses the whole field, not the block
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 38/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- bun, typescript
Research direction
Start with withVisualEditingPath.ts, markerExtractor.ts, and expandAndFocus.ts, then trace how block identity passes through the bridge message and veFocus URL. Run the named Vitest suites, especially findFieldElement.int.spec.ts, to cover marker extraction, routing, expansion, focus, and stale IDs. Done means the acceptance criteria pass for Live Preview and standalone URL routing, with field focus preserved when no block marker is present.
Written by the indexing model from the issue text.
Description
What happens
A rich text field is one edit target, and every Lexical block inside it shares the field's marker. "Edit" on the third block of a long article opens the right tab, focuses the editor, scrolls the field so its middle sits in the centre of the screen and plays the reveal over the whole field. The clicked block is not scrolled to, not expanded if it is collapsed and not highlighted, and since Lexical blocks open expanded by default, the editor scrolls past every open block to find it.
Expected
A renderer can mark a block node inside a rich text field, and "Edit" on it lands on that block: the admin scrolls the block into view, expands it if it is collapsed, focuses its first field and plays the reveal on the block. Without a block marker, everything behaves as today.
Reproduction
apps/cms installs the plugin with enrichment: "explicit" (plugins/index.ts#L404-L424), reads posts with context: { visualEditing: draft } (getPostBySlug.ts#L21), and a post's Content is a rich text field with four Lexical blocks (Posts/index.ts#L122-L140).
- In
apps/cms, fill.envfrom.env.exampleand runbun run dev(port 3333) - Open a post, give Content enough paragraphs to run several screens, insert a Code block near the end and save
- Open Live Preview and switch the floating toggle to Always
- Hover the Code block: the outline and the Edit badge cover the whole article, because the renderer marks only the wrapper (RichText/index.tsx#L111-L119) and the block converters have nothing to mark a block with (RichText/index.tsx#L67-L78)
- Click Edit: Content scrolls so its middle is centred, the caret lands in the editor, the reveal plays over the whole field, and the Code block stays off screen
The steps are read from the config and the source, not clicked through in this repo; the same behaviour was seen on 1.1.0 in a separate Payload 3 project.
Root cause
- Server:
enrichWithPathMetagives each block node'sfieldsits own_meta(enrichWithPathMeta.ts#L12-L39), thenencodeStegameets therichTextleaf, promotes one terminal marker to the field and deletes the inner ones (encodeStega.ts#L84-L97). The README documents rich text as a black box (README.md#L182-L203) - Client:
withVisualEditingPathcan only return the field's path (withVisualEditingPath.ts#L16-L27), and the identity sent to the admin has no slot below a field, in the message (constants.ts#L16-L25) or in theveFocusURL (buildAdminEditUrl.ts#L10-L26) - Admin: the path resolves to
field-content(resolveContainerChain.ts#L47-L59). A Lexical field has no element with that id, sofindFieldElementreturns its.field-typewrapper (expandAndFocus.ts#L156-L166), andfocusAndSweepcentres that wrapper withblock: "center", focuses the first[data-lexical-editor]inside it and sweeps the wrapper (expandAndFocus.ts#L299-L328)
Fix
Carry an optional block id from the renderer to the admin, and use it after the field is found.
src/internal/shared.ts:VeIdentitygainsblockId?: string;spreadVeIdentity,toMetaInfoandfromStegaPayloadcopy it, which carries it through the click handler and the target registry with no change of their ownsrc/constants.ts:DATA_VE_BLOCK_ID_ATTR = "data-ve-block-id", andblockId?: stringonVeOpenFieldMessagesrc/client/withVisualEditingPath.ts:withVisualEditingPath(value: unknown, options?: { blockId?: string }). A renderer marks a block from the Lexical JSON in its converter:withVisualEditingPath(content, { blockId: node.fields.id })src/client/overlay/markerExtractor.tsreads the attribute;createOverlay.tscomparesblockIdas well aspathbefore skipping a re-upsert (createOverlay.ts#L42-L52)src/client/buildAdminEditUrl.ts: appendveBlock=<id>src/admin/VisualEditingBridgeProvider.tsx: read and stripveBlocknext toveFocus, set it innavigateAndFocus, and passblockIdfrom the URL or the message throughfocusFieldPathintoexpandAndFocussrc/admin/expandAndFocus.ts:expandAndFocus(chain, fieldId, options?: { blockId?: string }). After the field element is found, wait (sameSTEP_BUDGET_MS) for the block inside it, click its toggle if it is collapsed, then runfocusAndSweepon the block, focusing the first input inside.collapsible__contentrather than the block-name input in the header. If the block does not turn up (deleted since the preview rendered, an inline block, changed markup), fall back to today's field focusREADME.md: a "Blocks inside rich text" subsection under "Editable richText and upload fields"
The admin selectors, read from Payload 3.90.1 and Lexical 0.50.0, the versions bun.lock locks:
- each block's form sits in an element whose
data-block-drawer-slugends in-<fields.id>(BlockComponent index.tsx#L109-L112, #L670-L675, slug prefix in Drawer index.tsx#L16-L17). It isdisplay: contents, so match the suffix withelement.dataset.blockDrawerSlug.endsWith("-" + blockId)and scroll itsclosest('[data-lexical-decorator="true"]'), the block's own DOM node (LexicalReconciler.ts#L719-L722) - the first
.collapsible__toggleinside it is the block's header toggle, collapsed when it carriescollapsible__toggle--collapsed(Collapsible index.tsx#L92-L95), the same classesrunInstructionalready clicks for rows (expandAndFocus.ts#L264-L273)
Existing users are unaffected: every new parameter is optional, and without blockId the attributes, the message, the URL and the admin behaviour are the same as 1.1.0. A newer frontend with an older admin, or the reverse, falls back to field focus. Both halves ship in this one package, so one minor bump covers them.
Acceptance criteria
-
withVisualEditingPath(content, { blockId: "abc" })returns today's attributes plusdata-ve-block-id="abc"; withoutoptionsthe result equals 1.1.0's - In
apps/cmswith the Code block converter marked, hovering the Code block outlines only the block, and hovering a paragraph still outlines the whole Content field - "Edit" on a Code block two or more screens below the top of Content scrolls that block into view and plays the reveal on it, from Live Preview (message route) and from a standalone frontend tab (
veFocusandveBlockURL route) - With the block collapsed in the admin beforehand, the same click expands it
- The caret lands in the block's first field, not in the block-name input or the editor root
- With an id that no longer exists in the document, the click focuses the field as today, with no console error
- Every existing test passes unchanged
Test plan
- Unit tests in
packages/payload-plugin-visual-editing/tests(vitest with jsdom,bun run test): extendwithVisualEditingPath.int.spec.ts,markerExtractor.int.spec.ts,buildAdminEditUrl.int.spec.ts,overlayClick.int.spec.tsandbridgeRouting.int.spec.tsxforblockIdandveBlock - In
findFieldElement.int.spec.ts, which already importsexpandAndFocus, add a fixture of Payload's block markup: two blocks, the second collapsed, a block-name input in its header and an input in its content. Assert the toggle is clicked,scrollIntoViewruns on the decorator element, focus lands in the content input, and a stale id falls back to the field - Manual in
apps/cms: mark the four block converters (passcontentintocreateJsxConverters), then run the reproduction from Live Preview and from a standalone frontend tab, whichapps/cmsroutes through the URL (VisualEditingEditRouter/index.tsx#L9-L31), once with the block expanded and once collapsed
Seen on 1.1.0, unchanged on main at b645ef0c.
The long-form brief carries the end-to-end trace, a code sketch of the admin step, the alternatives considered (an id in the path, a server-side block marker, the Lexical editor instance) and the edge cases, nested blocks and locales among them.
- Dominant language
- TypeScript
- Stars
- 34
- Forks
- 5
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 41
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from focusreactive/payload-plugins
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
focusreactive/payload-plugins#279 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
focusreactive/payload-plugins#263 ·
Maintainers usually reply within 1 day
-
comments, seo, analytics, and presets publish ESM that fails to load in Node.js (follow-up to #149)Open
Difficulty 3/5 1-2 days Newbie friendliness 62/100
focusreactive/payload-plugins#240 ·
Maintainers usually reply within 1 day
-
released released on @next
Difficulty 5/5 Over a week Newbie friendliness 35/100
focusreactive/payload-plugins#210 · 10 comments ·
Maintainers usually reply within 1 day
-
[translator] Re-extract the traversal engine into its own packageMay be free again @SearheiParkhamchuk claimed this 41 days ago, and no pull request is open. Openchore low priority translator
focusreactive/payload-plugins#203 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in focusreactive/payload-plugins
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nicobailon/pi-subagents#3420 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
openwatersio/slackwater.xyz#309 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
navikt/nav-enonicxp-frontend#3122 ·
Maintainers usually reply within 1 day
-
complexity → simple frontend performance
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
opencollective/opencollective#9200 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day