Skip to content

feat(next): export Versions diff surface as @payloadcms/next/views/diff#16498

Draft
tsemachh wants to merge 2 commits intopayloadcms:mainfrom
shefing:feat/export-diff-views-from-next
Draft

feat(next): export Versions diff surface as @payloadcms/next/views/diff#16498
tsemachh wants to merge 2 commits intopayloadcms:mainfrom
shefing:feat/export-diff-views-from-next

Conversation

@tsemachh
Copy link
Copy Markdown
Contributor

@tsemachh tsemachh commented May 6, 2026

Closes #16496

Summary

Adds a public, additive subpath export @payloadcms/next/views/diff that re-exports the field-by-field diff rendering surface today living privately under packages/next/src/views/Version/RenderFieldsToDiff/.

This lets plugin and integrator code build "review changes" / custom diff UIs (drawers, dashboards, notifications, PR-bot integrations, etc.) without forking or vendoring Payload's diff components or deep-importing from @payloadcms/next/dist/....

Public surface

import {
  RenderDiff,
  buildVersionFields,
  RenderVersionFieldsToDiff,
  DiffCollapser,
  defaultDiffComponents, // alias of diffComponents
  diffComponents,
  countChangedFields,
  countChangedFieldsInRows,
  fieldHasChanges,
  getFieldsForRowComparison,
  type BuildVersionFieldsArgs,
} from '@payloadcms/next/views/diff'

Changes

  • New packages/next/src/exports/views/diff.ts — pure re-export entry, no logic.
  • packages/next/package.json — adds "./views/diff" entry to both exports and publishConfig.exports, mirroring the shape of the existing "./views" entry.

Why not also point Version/index.tsx at the new public path?

The original plan considered making the internal Versions view import from @payloadcms/next/views/diff (or the relative exports/views/diff.js) so external and internal usage shared one source of truth. The repository's payload/no-imports-from-exports-dir lint rule explicitly forbids that pattern. The single-source-of-truth guarantee still holds because the new entry file is a pure re-export of the same internal modules Version/index.tsx consumes — there is no second copy of any symbol.

Backward compatibility

  • 100% additive: no existing import path changes, no symbol is renamed or removed.
  • Version/index.tsx is not modified — it continues to import from ./RenderFieldsToDiff/index.js as before.
  • No SCSS changes; existing per-field SCSS already ships in dist/.
  • No changes to payload, @payloadcms/translations, or any other package.

Tests

This PR is a pure re-export with no new behavior. The existing test/versions/ suite already exercises every symbol exposed here through the built-in Versions view. No new test was added.

If maintainers prefer a smoke test asserting the subpath resolves and exposes the listed names, happy to add one in test/_community/exports.test.ts (or a similar location) — let me know.

Concrete consumer

A planned @shefing/review-button plugin will use this surface to render a per-document diff in a side drawer. Without this PR, the plugin would have to vendor RenderFieldsToDiff/ and re-vendor on every Payload release.

Companion proposal

A separate issue (#16497) and forthcoming PR add a plugin-friendly config.admin.serverFunctions registry so plugins built on top of this export can wire themselves in without forcing integrators to edit (payload)/layout.tsx. This PR stands alone and does not depend on it.

Adds a public, additive subpath export so plugin and integrator code can
build custom diff UIs (e.g. "review changes" drawers) without vendoring
or deep-importing internal modules.

The new entry exposes:
  - RenderDiff
  - buildVersionFields (+ BuildVersionFieldsArgs)
  - RenderVersionFieldsToDiff (client component)
  - DiffCollapser (client component)
  - diffComponents (also re-exported as defaultDiffComponents)
  - countChangedFields, countChangedFieldsInRows
  - fieldHasChanges, getFieldsForRowComparison

100% additive: no existing imports change, no behavior change.

Closes payloadcms#16496

Co-authored-by: Junie <junie@jetbrains.com>
Co-authored-by: Junie <junie@jetbrains.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Export the Versions diff surface from @payloadcms/next for plugin authors

2 participants