Repository navigation
fix: scroll to and focus target field when navigating from visual editing - #185
Conversation
- Add missing `{...post.edit.excerpt}` annotation across all templates and demos
- Parse `?field=` search param in admin content edit route
- Add `useElementReady` hook to poll for DOM elements after async render
- Scroll to and focus the target field when navigating from visual editing
- Strip `?field=` from URL after scroll to prevent re-scroll on back navigation
- Add `id` to all field renderers (image, select, boolean, portableText) for scroll targeting
Replace Google Fonts CDN links with @fontsource-variable/inter and @fontsource/jetbrains-mono for privacy and offline reliability.
Add {...post.edit.content} to the article-content wrapper so the
Portable Text body participates in visual editing — clicking it in
edit mode now navigates to the admin editor with ?field=content,
triggering scroll-to-field.
…or rich text fields - useElementReady now accepts any CSS selector via querySelector instead of getElementById, making it more reusable - Scroll-to-field now focuses the .ProseMirror contenteditable div for portableText fields, falling back to the field container for all other field types
This reverts commit 35b8ba8.
🦋 Changeset detectedLatest commit: dfec3ff The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
- Remove selector from useElementReady dep array; use a ref so the effect fires once at mount rather than restarting when the selector string identity changes mid-poll - Normalize validateSearch to parse search.field safely from unknown input, dropping the pass-through that bypassed runtime validation - Drop redundant post.edit.content annotation on article-content wrapper — PortableText renders the inline editor automatically via getEditMeta; the wrapper annotation was suppressing it - Remove dead ProseMirror focus path; inline editor handles rich text
The extracted hook had a placement bug (hasAttempted set before rAF fires) and added indirection for a single call site. The inline effect with a hasScrolled ref is simpler, correct, and easier to reason about locally.
…rom useSearch. remove redundant hasScrolled check, URL is already updated. noticed that we need to defer the call to the next render now, so added requestIdleCallback & cleanup. shimmed at top of root component file
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
Pull request overview
Updates the admin content editor to support deep-linking to a specific field (via ?field=<name>) when navigating from visual editing, and expands demo/template field annotations so more fields can be targeted from the frontend.
Changes:
- Adds
?field=search validation and an idle-time scroll/focus + URL cleanup effect to the admin content edit route. - Ensures more field widgets render predictable
id="field-<name>"anchors for scroll targeting. - Annotates the
excerptfield in blog templates/demos so visual editing clicks can navigate to that field in the admin.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| templates/blog/src/pages/posts/[slug].astro | Adds {...post.edit.excerpt} to excerpt markup for visual editing navigation. |
| templates/blog-cloudflare/src/pages/posts/[slug].astro | Same excerpt annotation for the Cloudflare blog template. |
| packages/admin/src/router.tsx | Validates field search param and performs post-load scroll/focus + strips param; adds requestIdleCallback polyfill. |
| packages/admin/src/components/ContentEditor.tsx | Adds id anchors for additional field kinds (Switch/Select/Image/PortableText wrapper) to enable scroll targeting. |
| demos/simple/src/pages/posts/[slug].astro | Adds excerpt annotation for the simple demo. |
| demos/preview/src/pages/posts/[slug].astro | Adds excerpt annotation for the preview demo. |
| demos/postgres/src/pages/posts/[slug].astro | Adds excerpt annotation for the postgres demo. |
| demos/playground/src/pages/posts/[slug].astro | Adds excerpt annotation for the playground demo. |
| demos/cloudflare/src/pages/posts/[slug].astro | Adds excerpt annotation for the cloudflare demo. |
| .changeset/twenty-friends-sell.md | Publishes a patch changeset for the admin fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| React.useEffect(() => { | ||
| if (typeof searchParams.field !== "string" || isLoading) return; | ||
|
|
||
| const timeoutId = requestIdleCallback(() => { | ||
| const el = document.getElementById(`field-${searchParams.field}`); |
There was a problem hiding this comment.
The scroll/focus effect can run before the editor is actually rendered: it only gates on isLoading, but this component can still be returning <LoadingScreen /> when manifest is not yet loaded. In that case the idle callback won’t find the field element and the effect won’t rerun (since manifest isn’t a dependency). Gate on !!manifest (and/or !!item) and include it in the effect deps so the behavior reliably triggers once the editor is mounted.
| el.scrollIntoView({ behavior: "smooth", block: "center" }); | ||
| el.focus(); |
There was a problem hiding this comment.
el.focus() may be a no-op for fields where the ID is attached to a non-focusable wrapper (e.g., portableText/image use a <div id=...>). Consider focusing the first focusable descendant (input/textarea/button/[contenteditable]/[tabindex]) and using focus({ preventScroll: true }) to avoid undoing scrollIntoView.
| el.scrollIntoView({ behavior: "smooth", block: "center" }); | |
| el.focus(); | |
| const focusableSelector = [ | |
| "input", | |
| "textarea", | |
| "select", | |
| "button", | |
| "a[href]", | |
| '[contenteditable="true"]', | |
| '[tabindex]:not([tabindex="-1"])', | |
| ].join(", "); | |
| const focusTarget = | |
| el instanceof HTMLElement && | |
| (el.matches(focusableSelector) | |
| ? el | |
| : el.querySelector<HTMLElement>(focusableSelector)); | |
| el.scrollIntoView({ behavior: "smooth", block: "center" }); | |
| focusTarget?.focus({ preventScroll: true }); |
| React.useEffect(() => { | ||
| if (typeof searchParams.field !== "string" || isLoading) return; | ||
|
|
||
| const timeoutId = requestIdleCallback(() => { | ||
| const el = document.getElementById(`field-${searchParams.field}`); | ||
| if (el) { | ||
| el.scrollIntoView({ behavior: "smooth", block: "center" }); | ||
| el.focus(); | ||
| const { field: _, ...preservedSearch } = searchParams; | ||
| void navigate({ search: preservedSearch as never, replace: true }); | ||
| } | ||
| }); | ||
| return () => cancelIdleCallback(timeoutId); | ||
| }, [searchParams, isLoading, navigate]); |
There was a problem hiding this comment.
This new ?field= navigation behavior (idle scroll, focus, and URL param stripping) isn’t covered by existing admin router/component tests. Since packages/admin/tests/router.test.tsx exists, adding a test that navigates to /content/$collection/$id?field=..., stubs scrollIntoView/focus, and asserts the param is removed would help prevent regressions.
…ting (emdash-cms#185) * fix: visual editing field navigation and scroll-to-field in admin - Add missing `{...post.edit.excerpt}` annotation across all templates and demos - Parse `?field=` search param in admin content edit route - Add `useElementReady` hook to poll for DOM elements after async render - Scroll to and focus the target field when navigating from visual editing - Strip `?field=` from URL after scroll to prevent re-scroll on back navigation - Add `id` to all field renderers (image, select, boolean, portableText) for scroll targeting * fix: self-host Inter and JetBrains Mono via fontsource Replace Google Fonts CDN links with @fontsource-variable/inter and @fontsource/jetbrains-mono for privacy and offline reliability. * fix: annotate content field for visual editing in simple demo Add {...post.edit.content} to the article-content wrapper so the Portable Text body participates in visual editing — clicking it in edit mode now navigates to the admin editor with ?field=content, triggering scroll-to-field. * fix: generalize useElementReady to CSS selectors, focus ProseMirror for rich text fields - useElementReady now accepts any CSS selector via querySelector instead of getElementById, making it more reusable - Scroll-to-field now focuses the .ProseMirror contenteditable div for portableText fields, falling back to the field container for all other field types * chore: ignore CLAUDE.local.md and .playwright-mcp * Revert "fix: self-host Inter and JetBrains Mono via fontsource" This reverts commit 35b8ba8. * refactor: use useStableCallback in useElementReady * chore: ignore *.local.* files for personal cursor rules * fix: stabilize useElementReady deps and normalize validateSearch - Remove selector from useElementReady dep array; use a ref so the effect fires once at mount rather than restarting when the selector string identity changes mid-poll - Normalize validateSearch to parse search.field safely from unknown input, dropping the pass-through that bypassed runtime validation - Drop redundant post.edit.content annotation on article-content wrapper — PortableText renders the inline editor automatically via getEditMeta; the wrapper annotation was suppressing it - Remove dead ProseMirror focus path; inline editor handles rich text * refactor: replace useElementReady hook with inline effect The extracted hook had a placement bug (hasAttempted set before rAF fires) and added indirection for a single call site. The inline effect with a hasScrolled ref is simpler, correct, and easier to reason about locally. * revert: restore .gitignore to main * fix: pass id directly to Select instead of wrapper div * fix: pass id directly to Select instead of wrapper div * fix: remove spread object from useEffect deps, use stable reference from useSearch. remove redundant hasScrolled check, URL is already updated. noticed that we need to defer the call to the next render now, so added requestIdleCallback & cleanup. shimmed at top of root component file * chore: add changelist entry 🦋 --------- Co-authored-by: Matt Kane <[email protected]>
What does this PR do?
When navigating from visual editing with
?field=<name>, the admin content editor scrolls to and focuses the target field once content has loaded, then strips the param from the URL.Also annotates the excerpt field in
demos/simplewith{...post.edit.excerpt}so clicking it in edit mode opens the admin editor navigated to that field.Type of change
Checklist
pnpm typecheckpassespnpm --silent lint:json | jq '.diagnostics | length'returns 0pnpm testpasses (core package: 2095 tests passing)pnpm formathas been runAI-generated code disclosure
Screenshots / test output
Verified manually:
?field=<name>?field=param is stripped from the URL after scroll