Skip to content

fix: pass draft flag when fetching parent documents for breadcrumb generation#62

Closed
Copilot wants to merge 7 commits intomainfrom
copilot/fix-draft-flag-breadcrumbs
Closed

fix: pass draft flag when fetching parent documents for breadcrumb generation#62
Copilot wants to merge 7 commits intomainfrom
copilot/fix-draft-flag-breadcrumbs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 15, 2026

findByIDCached in getBreadcrumbs.ts never passed draft when fetching parent documents, causing draft-only parents to be unfindable and stale published breadcrumbs to appear in preview mode.

Changes

  • getBreadcrumbs.ts — Added draft?: boolean parameter; passes it to findByIDCached. Cache key now includes draft/published suffix to prevent cross-contamination.
  • setPageVirtualFields.ts — Added draft?: boolean parameter; threads it through to getBreadcrumbs.
  • setVirtualFields.ts — Added draftFromRequest helper that reads req.query.draft (handles both "true" string from REST and boolean true). Both setVirtualFieldsBeforeRead and setVirtualFieldsAfterChange derive and forward the flag.

Draft detection

Draft context is derived from req.query.draft, which Payload populates from the URL query string for REST requests (e.g. admin, live preview with ?draft=true). Local API callers that need draft breadcrumbs can pass req: { query: { draft: 'true' } }.

// Before: parent always fetched as published
await req.payload.findByID({ id, collection, locale, ... })

// After: draft flag forwarded from the originating request
await req.payload.findByID({ id, collection, locale, draft, ... })

Tests

Added describe('Draft flag is forwarded to parent document fetch during breadcrumb computation') in both localized and unlocalized test suites covering:

  • draft: true reaches the nested parent findByID when req.query.draft = 'true'
  • Non-draft requests leave draft unset (no regression)
  • Child breadcrumbs reflect the draft parent slug when fetched in draft mode vs. the published slug otherwise

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.payloadcms.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/payload-plugins/payload-plugins/pages/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.3_sass@1.77.4_tsx@4.21.0/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/payload-plugins/payload-plugins/pages/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.3_sass@1.77.4_tsx@4.21.0/node_modules/vitest/dist/workers/forks.js (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/payload-plugins/payload-plugins/pages/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.3_sass@1.77.4_tsx@4.21.0/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/payload-plugins/payload-plugins/pages/node_modules/.pnpm/vitest@4.0.18_@types+node@25.2.3_sass@1.77.4_tsx@4.21.0/node_modules/vitest/dist/workers/forks.js /home/REDACTED/woradd /home/REDACTED/wor. bash --no�� --noprofile /home/REDACTED/work/payload-plugins/payload-plugins/alt-text/src/plugin.ts /home/REDACTED/work/_temp/ghcca-node/node/bin/grep /home/REDACTED/worgit /home/REDACTED/worrev-parse /home/REDACTED/worHEAD grep (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>fix: pass draft flag when fetching parent documents for breadcrumb generation</issue_title>
<issue_description>## Problem

In getBreadcrumbs.ts, the findByID call for fetching parent documents does not pass a draft parameter. Payload defaults to returning the published version, which causes two issues:

  1. Draft-only parents: If a parent page has never been published, findByID won't find it and breadcrumb generation throws an error.
  2. Stale breadcrumbs in preview: If a parent page has draft changes to its slug or title, child pages in live preview still show the old published breadcrumbs. The preview is inconsistent with the actual draft state.

Proposed Solution

Pass the draft flag through to the parent findByID call in getBreadcrumbs.ts. The draft context should be derived from the current request.

Note: For the locale: 'all' + draft combination, Payload does not support fetching all locales of a draft document in a single query. This edge case may require fetching each locale separately and could be handled as a follow-up.

Testing

Add tests for this.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…neration

Co-authored-by: jhb-dev <20878653+jhb-dev@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix passing draft flag for parent document fetching fix: pass draft flag when fetching parent documents for breadcrumb generation Mar 15, 2026
Copilot AI requested a review from jhb-dev March 15, 2026 16:25
@jhb-dev jhb-dev closed this Apr 2, 2026
@jhb-dev jhb-dev deleted the copilot/fix-draft-flag-breadcrumbs branch April 2, 2026 18:32
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.

fix: pass draft flag when fetching parent documents for breadcrumb generation

2 participants