Skip to content

Preview button throws error when preview URL is null #14241

@jhb-dev

Description

@jhb-dev

Describe the Bug

First, thanks @jacobsfletch for the ongoing work on improving Live Preview! This issue is related to #14012, but concerns the Preview button (not the Live Preview button):

When the function that generates the preview URL returns null (e.g., because the page slug is not defined yet), the Preview button is still rendered. Clicking it shows the error message: “There was a problem previewing this document.”

Current behavior:
If function that generates the preview URL returns null, the Preview button still appears. On click, Payload shows: “There was a problem previewing this document.”

Expected behavior:
The Preview button should be conditionally hidden when no URL is available — consistent with the Live Preview button behavior.

2025-10-17.18-56-48.mp4

Link to the code that reproduces this issue

https://github.com/jhb-dev/payload-conditional-preview-issue

Reproduction Steps

  1. Run the Payload instance of the reproduction repository.
  2. Open the Pages collection and click Create new.
  3. Ensure no slug is set.
  4. Click the Preview button.
  5. Observe the error: “There was a problem previewing this document.”

Which area(s) are affected? (Select all that apply)

area: ui

Environment Info

Binaries:
  Node: 24.3.0
  npm: 11.4.2
  Yarn: N/A
  pnpm: 10.12.4
Relevant Packages:
  payload: 3.60.0
  next: 15.4.4
  @payloadcms/db-mongodb: 3.60.0
  @payloadcms/next/utilities: 3.60.0
  @payloadcms/payload-cloud: 3.60.0
  @payloadcms/richtext-lexical: 3.60.0
  @payloadcms/ui/shared: 3.60.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 14

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions