visual-editing: "Edit" on a block inside a rich text field focuses the whole field, not the block
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 38/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- bun, typescript
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 34
- Fork
- 5
- Merge medio
- 2g 4h
- PR unite (30g)
- 41
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di focusreactive/payload-plugins
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
focusreactive/payload-plugins#279 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
focusreactive/payload-plugins#263 ·
I maintainer di solito rispondono entro 1 giorno
-
comments, seo, analytics, and presets publish ESM that fails to load in Node.js (follow-up to #149)Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
focusreactive/payload-plugins#240 ·
I maintainer di solito rispondono entro 1 giorno
-
released released on @next
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
focusreactive/payload-plugins#210 · 10 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[translator] Re-extract the traversal engine into its own packageForse di nuovo libera @SearheiParkhamchuk l’ha presa 41 giorni fa e non c’è nessuna pull request aperta. Apertachore low priority translator
focusreactive/payload-plugins#203 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di focusreactive/payload-plugins
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nicobailon/pi-subagents#3420 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
openwatersio/slackwater.xyz#309 ·
I maintainer di solito rispondono entro 1 giorno
-
Mer utskriftsvennlig stylingAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
navikt/nav-enonicxp-frontend#3122 ·
I maintainer di solito rispondono entro 1 giorno
-
complexity → simple frontend performance
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
opencollective/opencollective#9200 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno