Skip to content

Fix publishedAt field: hook bug, standardize config, remove misleading description#1091

Draft
busbyk wants to merge 3 commits into
mainfrom
fix/published-at-field-issues
Draft

Fix publishedAt field: hook bug, standardize config, remove misleading description#1091
busbyk wants to merge 3 commits into
mainfrom
fix/published-at-field-issues

Conversation

@busbyk
Copy link
Copy Markdown
Collaborator

@busbyk busbyk commented May 26, 2026

Description

  1. Hook bug - The populatePublishedAt hook always overwrote publishedAt during updates, clobbering user-provided dates. Restructured to only override when explicitly needed.
  2. Inconsistent picker configs - Pages and HomePages used day-only pickers while Posts used dayAndTime. Standardized all three to dayAndTime.
  3. Misleading description - Removed the description on Pages publishedAt field that incorrectly claimed it affects page visibility.
  4. UI stale state after unpublish - Identified as a Payload core bug: UnpublishButton resets form with stale dataFromProps instead of server response. DB is correct; cosmetic issue resolves on reload. See publishedAt field issues #878 comment for root cause analysis.

Related Issues

Fixes #878 (items 1, 3, 4 - item 2 is a Payload core bug)
Supersedes #1089 (closed), Closes #1087 (duplicate of #878)

Key Changes

  • src/hooks/populatePublishedAt.ts - Restructured update logic to preserve user-provided dates
  • src/collections/Pages/index.ts - Added dayAndTime picker, removed misleading description
  • src/collections/HomePages/index.tsx - Added dayAndTime picker
  • src/payload-types.ts - Regenerated (removed stale description comment)
  • __tests__/server/populatePublishedAt.server.test.ts - 7 unit tests for all hook code paths
  • __tests__/e2e/admin/collections/published-at.e2e.spec.ts - 5 e2e tests for field behavior

How to test

Unit tests: pnpm test -- __tests__/server/populatePublishedAt.server.test.ts

E2e tests: pnpm exec playwright test __tests__/e2e/admin/collections/published-at.e2e.spec.ts

Manual: Edit a published post date (should persist), unpublish (clears after reload), check dayAndTime picker on Pages/HomePages.

Migration Explanation

No migration needed - field admin config changes only.

Future enhancements / Questions

busbyk and others added 2 commits May 26, 2026 13:50
- Fix populatePublishedAt hook clobbering user-provided dates on update
- Standardize publishedAt to dayAndTime picker on Pages and HomePages
  (matching Posts)
- Remove misleading description from Pages publishedAt field that
  incorrectly claimed the field affects page visibility

Fixes #878

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Unit tests cover the populatePublishedAt hook: auto-set on create,
preserve user dates, clear on unpublish, edge cases. E2e tests verify
the field renders with dayAndTime picker on Posts and Pages, user-set
dates persist across save/reload, and the misleading description is
removed from Pages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

publishedAt field issues Post publish date issue

1 participant