Skip to content

fix: make artisanpack/post-title editable inline against the live entity - #548

Merged
ViewFromTheBox merged 2 commits into
release/1.0from
bugfix/546-title-block-not-updating-on-type
Jun 8, 2026
Merged

ViewFromTheBox merged 2 commits into
release/1.0from
bugfix/546-title-block-not-updating-on-type

Conversation

@ViewFromTheBox

@ViewFromTheBox ViewFromTheBox commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Description

The artisanpack/post-title block edit was a readonly placeholder, so focusing the Title block in the post editor canvas and typing did nothing — the canvas displayed the loaded title (via useEntityRecord) but offered no setter path. This PR replaces the placeholder with a hybrid edit that becomes editable inline when a single page/post is in scope.

Closes: #546

Type of Change

  • Bug fix (fixes an issue)

Related Issue

Issue: #546

Motivation and Context

Users expect the post-title block to behave like upstream core/post-title — type a character, watch the canvas update in real time, and have the edit ride the same metadata-save loop as the sidebar fields. This PR closes that gap without regressing the readonly preview paths the _resolved* stamp, query-loop preview, and live-entity-as-readonly callers depend on.

Changes Made

  • Rewrote resources/js/visual-editor/blocks/post-title/edit.tsx as a hybrid edit with explicit priority:
    1. _resolvedTitle stamped → readonly (unchanged).
    2. artisanpack/postPreview query-loop context → readonly preview (unchanged).
    3. Live entity in scope (postType + postId, no queryId) → editable PlainText wired through the core-data shim's useEntityProp('postType', postType, 'title', postId).
    4. No entity in scope → placeholder label (unchanged).
  • Typing dispatches editEntityRecord via useEntityProp's setter; editor-app's existing stagedEntityEdits useSelect picks up the edit and re-arms the metadata-save debounce on the same cycle as sidebar edits — no new wiring on the persistence side.
  • Added a single-mounted-Probe regression test for useEntityProp in core-data-shim.test.tsx that confirms the shim's setter does re-render the consumer (rules out the OP's hypothesis about the setter not firing).
  • Updated entity-placeholder-live-entity.test.tsx with a PlainText mock, switched live-entity assertions from getByText to getByDisplayValue, added a typing test that asserts both the visible re-render and the staged getEntityRecordEdits payload, and added a query-loop-readonly assertion.
  • Added a matching PlainText mock to entity-placeholder-query-preview.test.tsx so the edit module's import resolves.

How Has This Been Tested?

Testing Environment:

  • Operating System: macOS (Darwin 25.5.0)
  • Browser: Safari (Herd dev)
  • PHP Version: 8.4.3
  • Project Version: release/1.0

Tests Performed:

  1. Full JS suite — 1845/1845 passing (npx vitest run).
  2. Full PHP suite (post-title scope) — 7/7 passing (./vendor/bin/pest --filter=PostTitle).
  3. Manual verification in the post editor: focused the title block on a real post, typed characters, watched the displayed value update in real time and the save indicator fire on the debounce.
  4. Manual verification inside an artisanpack/query loop: title block still renders as readonly preview (not editable).

Accessibility Tests Run

  • Keyboard navigation tested — PlainText uses the same focus/typing semantics as upstream core/post-title.
  • Screen reader tested
  • Color contrast verified — unchanged from the readonly placeholder.
  • ARIA labels checked — inherited from useBlockProps() block wrapper.

Details: No new ARIA surface introduced; the editable element is @wordpress/block-editor's PlainText, which carries the same labelling story as the rest of the editor's inline edit fields.

Tests Added

  • Unit tests added/updated
  • Integration tests added/updated
  • All tests passing

Test details:

  • useEntityProp re-render regression test against a single mounted Probe (core-data-shim.test.tsx).
  • Typing test that asserts both the visible re-render and the staged entity edit (entity-placeholder-live-entity.test.tsx).
  • Query-loop readonly assertion (entity-placeholder-live-entity.test.tsx).
  • Updated live-entity assertions to getByDisplayValue for the now-editable post-title.

Documentation

Pre-Submission Checklist

  • Followed contributing guidelines
  • Checked for other open PRs for same update
  • Code passes all tests
  • Code has been linted (no eslint config in repo; CodeRabbit review pass returned 0 findings)
  • Accessibility tests completed
  • Code follows project style guide
  • Self-review completed
  • Comments added for complex code
  • No new warnings generated

Summary by CodeRabbit

  • Tests

    • Expanded test coverage for post-title and site-preview behaviors, validating live-entity editing, numeric postId handling, textarea-based editable state, readonly query-loop previews, and resolver/placeholder precedence.
  • Refactor

    • Replaced the generic placeholder setup with a dedicated Post Title edit/preview component to better handle live entity rendering, query-loop previews, tag-level output, and placeholder styling.

The post-title block edit was a readonly placeholder, so focusing it and
typing did nothing — the canvas displayed the loaded title (via
`useEntityRecord`) but offered no setter path. Replaces the placeholder
with a hybrid edit:

  1. Stamped `_resolvedTitle` attribute → readonly (unchanged).
  2. `artisanpack/postPreview` query-loop context → readonly preview
     (unchanged).
  3. Live entity in scope (`postType` + `postId`, no `queryId`) →
     editable `PlainText` wired through the core-data shim's
     `useEntityProp('postType', postType, 'title', postId)`. Typing
     stages an `editEntityRecord` edit, the canvas re-renders via
     `useSelect`'s subscription, and `editor-app`'s `stagedEntityEdits`
     watch re-arms the metadata-save debounce on the same cycle as
     sidebar edits.
  4. No entity in scope → placeholder label (unchanged).

Adds a single-mounted-Probe regression test for `useEntityProp` to
confirm the shim's setter does re-render the consumer, and updates the
live-entity test suite with a PlainText mock + a typing test that
asserts both the visible re-render and the staged
`getEntityRecordEdits` payload.

Closes #546

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6fe80822-1bf3-464a-8060-9d25b3bf3c5a

📥 Commits

Reviewing files that changed from the base of the PR and between ff59419 and 802f40f.

📒 Files selected for processing (1)
  • resources/js/visual-editor/blocks/post-title/edit.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • resources/js/visual-editor/blocks/post-title/edit.tsx

📝 Walkthrough

Walkthrough

Replace factory placeholder with PostTitleEdit: stamped resolved → query-preview → live editable via useEntityProp → placeholder. Add PlainText textarea test mocks, rewrite post-title tests to assert textarea display-value and typing/edit propagation, and add a useEntityProp setter re-render test.

Changes

Post Title Block Live Entity Editing

Layer / File(s) Summary
PostTitleEdit component and helpers
resources/js/visual-editor/blocks/post-title/edit.tsx
Introduced file doc and helpers for parsing/coercion and tag mapping. Implemented PostTitleEdit that enforces rendering precedence: stamped _resolvedTitle, query-preview title, live editable PlainText bound to useEntityProp, or dashed placeholder fallback.
Test mock infrastructure for PlainText
resources/js/visual-editor/blocks/_shared/__tests__/entity-placeholder-live-entity.test.tsx, resources/js/visual-editor/blocks/_shared/__tests__/entity-placeholder-query-preview.test.tsx
Expanded @wordpress/block-editor mock to add a controlled PlainText textarea stub (for value/onChange/placeholder) and added act/fireEvent imports to support interactive RTL assertions.
Live entity test coverage for editable title
resources/js/visual-editor/blocks/_shared/__tests__/entity-placeholder-live-entity.test.tsx
Rewrote post-title tests to assert the displayed textarea value for live entity title and to ensure placeholder doesn't show. Adjusted raw/rendered title test to use display-value queries. Added numeric-string postId acceptance test, typing updates reflected in textarea and core-data edits, and query-loop readonly preview test (no textarea).
useEntityProp setter re-render verification
resources/js/visual-editor/vendor/__tests__/core-data-shim.test.tsx
Added a test mounting a Probe consumer to verify invoking the setter from useEntityProp triggers a re-render and updates the consumer's displayed value without remounting.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I nibble keys and hop with glee,
A textarea now hears my plea,
Titles change as fingers play,
Edits saved and shown today—
Hopping off, content and free.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: making the post-title block editable inline against the live entity instead of readonly.
Linked Issues check ✅ Passed The PR comprehensively addresses issue #546 by fixing the useEntityProp setter to properly dispatch editEntityRecord and trigger re-renders, enabling inline editing of the post title with live value updates.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the post-title block editability issue: test mocks, useEntityProp hook tests, PostTitleEdit component rewrite, and entity-placeholder test updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/546-title-block-not-updating-on-type

Comment @coderabbitai help to get the list of available commands and usage tips.

@ViewFromTheBox ViewFromTheBox moved this from Backlog to In Review in ArtisanPack UI Overview Jun 8, 2026
@ViewFromTheBox
ViewFromTheBox marked this pull request as ready for review June 8, 2026 20:57

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
resources/js/visual-editor/blocks/post-title/edit.tsx (1)

161-161: 💤 Low value

Consider adding a clarifying comment for the condition.

The condition titleText !== '' || editedTitle !== undefined correctly handles the resolver-in-flight case (as documented in the module docblock), but the logic is subtle. A brief inline comment would help future maintainers understand why we check both conditions:

// Render editable PlainText if the title is non-empty OR if the
// entity has resolved (editedTitle !== undefined). This falls through
// to the placeholder only when the resolver is still in flight.
if ( titleText !== '' || editedTitle !== undefined ) {

This is a minor readability improvement rather than a functional issue.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@resources/js/visual-editor/blocks/post-title/edit.tsx` at line 161, Add a
brief inline comment above the conditional that checks "titleText !== '' ||
editedTitle !== undefined" explaining intent: clarify that we render the
editable PlainText when the title has content OR when the entity has resolved
(editedTitle !== undefined), and only show the placeholder while the resolver is
still in flight; reference the variables titleText and editedTitle and place the
comment immediately above the if condition in edit.tsx near the PlainText
rendering logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@resources/js/visual-editor/blocks/post-title/edit.tsx`:
- Line 161: Add a brief inline comment above the conditional that checks
"titleText !== '' || editedTitle !== undefined" explaining intent: clarify that
we render the editable PlainText when the title has content OR when the entity
has resolved (editedTitle !== undefined), and only show the placeholder while
the resolver is still in flight; reference the variables titleText and
editedTitle and place the comment immediately above the if condition in edit.tsx
near the PlainText rendering logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d60bfc9a-be46-44c2-a788-dad413f9c7ed

📥 Commits

Reviewing files that changed from the base of the PR and between 62b152b and ff59419.

📒 Files selected for processing (4)
  • resources/js/visual-editor/blocks/_shared/__tests__/entity-placeholder-live-entity.test.tsx
  • resources/js/visual-editor/blocks/_shared/__tests__/entity-placeholder-query-preview.test.tsx
  • resources/js/visual-editor/blocks/post-title/edit.tsx
  • resources/js/visual-editor/vendor/__tests__/core-data-shim.test.tsx

Inline comment explaining the editable-vs-placeholder branch on
`titleText !== '' || editedTitle !== undefined`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@ViewFromTheBox
ViewFromTheBox merged commit 69a46a4 into release/1.0 Jun 8, 2026
6 checks passed
@ViewFromTheBox
ViewFromTheBox deleted the bugfix/546-title-block-not-updating-on-type branch June 8, 2026 21:03
@github-project-automation github-project-automation Bot moved this from In Review to Done in ArtisanPack UI Overview Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Post editor title block reads correctly but does not update as the user types

1 participant