Skip to content

fix: resolve hierarchy path ancestors using the request draft intent - #17269

Open
thribhuvan003 wants to merge 1 commit into
payloadcms:mainfrom
thribhuvan003:fix/hierarchy-afterread-draft-intent
Open

thribhuvan003 wants to merge 1 commit into
payloadcms:mainfrom
thribhuvan003:fix/hierarchy-afterread-draft-intent

Conversation

@thribhuvan003

Copy link
Copy Markdown

What?

When a hierarchy collection document is read with draft: true, the computed _h_slugPath / _h_titlePath now resolve the ancestor chain at the draft version the request asked for. Previously the draft flag passed to computePaths came from the document's own _status.

Why?

doc._status only says whether this specific document has unpublished changes, it says nothing about the request. So a published child read in live preview (draft: true) walked its ancestors with draft: false and got the published parent titles/slugs. With a parent that had a draft-only rename, the child's breadcrumb showed the published slug instead of the draft one.

How?

The hierarchy plugin's own beforeOperation hook already runs for read operations and receives the operation args, so it now stashes args.draft in context.hierarchyRequestDraft (same pattern as the existing computeHierarchyPathsViaSelect flag). afterRead prefers that value and only falls back to the old doc._status === 'draft' check for paths that don't go through a read operation. draft is already a boolean by the time the hook runs on every surface (REST coerces it via parseParams, local API and GraphQL pass it directly).

Added an int test: published parent with a draft-only rename plus a published child. Reading the child with draft: true yields the draft parent path, and with draft: false still yields the published one. The first assertion fails without the fix, the full hierarchy suite (35 tests) passes with it.

Fixes #17223

@jhb-dev

jhb-dev commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Hi @thribhuvan003,

Thanks for the PR addressing my issue!

That said, I think the more robust and safer fix would be to expose the "draft" argument to the hook, as suggested in the issue: #16180.

@thribhuvan003

Copy link
Copy Markdown
Author

hey, thanks for taking a look! i agree exposing draft in the hook args (#16180) is the cleaner long-term shape — i kept this one inside the plugin on purpose since changing the public hook signature touches every operation and felt like it needed a maintainer call first. happy to rework this to add the arg if that's the direction they want, or land the narrow fix now and do #16180 as a follow-up.

This branch has not been deployed

No deployments
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.

hierarchy: afterRead hook uses doc._status instead of request draft intent when computing paths

2 participants