[v4] Document controls: empty `__icon-buttons` wrapper doubles the gap before Save

Open Beginner friendly
#19,395 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript
Domain
frontend

Research direction

Start at packages/ui/src/elements/DocumentControls/index.tsx, especially lines 306–317, where the icon buttons wrapper is rendered. Check the related styles for .doc-controls__controls and the reproduction steps to confirm the extra gap when the wrapper has no children. Done means the gap before Save stays 8px in both cases; no test file is named in the issue.

Written by the indexing model from the issue text.

Description

area: ui Bug created-by: Contributor status: needs-triage v3
Describe the Bug.

DocumentControls always renders <div className="doc-controls__icon-buttons">, even when none of its children render (live preview toggler, preview button, schedule publish button). The wrapper is still a flex item of .doc-controls__controls, which has gap: var(--spacer-2). So when it's empty, the space between whatever comes before it and the Save / Publish button doubles: 8px + 0px + 8px = 16px.

You can see this with any admin.components.edit.beforeDocumentControls component on a collection that has no live preview, no admin.preview and no scheduled publish. The custom control sits noticeably further from Save than the other controls in the row are from each other.

Expected: the gap before Save is 8px whether or not the icon buttons render.

Without icon buttons (bug, 16px):

Image

With admin.preview (8px + 8px) :

Image

Measured getBoundingClientRect() of the .doc-controls__controls children:

Collection Marker → icon-buttons icon-buttons width icon-buttons → Save Marker → Save
posts (no icon buttons) 8px 0px 8px 16px
posts-with-preview 8px 24px 8px n/a (preview button in between)
Link to the code that reproduces this issue

https://github.com/VeiaG/payload-4-reproductions/tree/repro-doc-controls-empty-icon-buttons-gap

Source: packages/ui/src/elements/DocumentControls/index.tsx#L306-L317

<div className={`${baseClass}__icon-buttons`}>
  {isLivePreviewEnabled && !isInDrawer && <LivePreviewToggler />}
  {(collectionConfig?.admin.preview || globalConfig?.admin.preview) && (
    <RenderCustomComponent CustomComponent={CustomPreviewButton} Fallback={<PreviewButton />} />
  )}
  {hasScheduledPublishEnabled(collectionConfig || globalConfig) && !isTrashed && (
    <SchedulePublishButton disabled={readOnlyForIncomingUser} />
  )}
</div>
Reproduction Steps
  1. pnpm install && pnpm dev, then open http://localhost:3000/admin.
  2. Open the seeded doc in Posts. Its beforeDocumentControls renders a 32px red square, and the collection has no live preview, admin.preview or scheduled publish.
  3. The square sits 16px from Save. In devtools there is an empty .doc-controls__icon-buttons div between them.
  4. Open the seeded doc in Posts With Preview. It's the same collection plus admin.preview, and the gaps are 8px on each side of the preview button, as intended.

Same result on TanStack Start (pnpm dev:tanstack, checked on beta.6).

Environment Info
payload: 4.0.0-beta.7
@payloadcms/ui: 4.0.0-beta.7
@payloadcms/next: 4.0.0-beta.7 (next 16.4.4)
@payloadcms/tanstack-start: 4.0.0-beta.7
Node: 24
OS: Windows 11
Dominant language
TypeScript
Stars
45.6k
Forks
4.4k
Avg merge
1d 23h
Merged PRs (30d)
237

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from payloadcms/payload

All issues in payloadcms/payload

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.