Skip to content

fix: cms preview, media tenant isolation, post hero image, test-migration#420

Merged
hakalb merged 6 commits intomainfrom
fix/cms-preview-route-redirect
Apr 23, 2026
Merged

fix: cms preview, media tenant isolation, post hero image, test-migration#420
hakalb merged 6 commits intomainfrom
fix/cms-preview-route-redirect

Conversation

@hakalb
Copy link
Copy Markdown
Member

@hakalb hakalb commented Apr 22, 2026

Summary

  • Preview route: Fix open-redirect, tenant-scoped draft mode, and clear stale __prerender_bypass cookie when no payload-token is present
  • Media tenant isolation: Prefix filenames with tenant slug, store files in tenant S3 folders via prefix field, compound unique index (filename, prefix) to prevent cross-tenant collisions on re-seed; filenameWithoutPrefix computed field for clean admin display
  • Post hero image (COD-383): Register image block in RichText JSX converters (it was missing — blocks embedded in post content were silently dropped); fix URL construction double-slash in ImageBlock; use ImageBlock for hero image rendering in RenderPost
  • test-migration: Fix readiness check to poll via TCP from the host (SELECT 1) instead of the UNIX socket inside the container, preventing a race where psql connects before PostgreSQL's TCP port is fully bound

Test plan

  • Seed CMS with S3 enabled — verify files land in tenant folders (moon/moon-*.jpg, star/star-*.jpg, etc.) with no duplicate-filename errors on re-seed
  • Open a post with an embedded image block — verify image renders correctly
  • Set a hero image on a post — verify it appears on the post page
  • Enter draft preview mode — verify redirect works and stale cookie is cleared on exit
  • Run pnpm cdwrtest-migration — verify schema restore no longer fails with "server closed the connection unexpectedly"

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 22, 2026 22:40
@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 22, 2026

View your CI Pipeline Execution ↗ for commit f017db3

Command Status Duration Result
nx affected -t e2e --exclude *,!tag:scope:nx-pa... ✅ Succeeded 9m 35s View ↗
nx affected -t integration-test -c ci ✅ Succeeded 2m 29s View ↗
nx affected -t e2e -c ci --exclude nx-payload-e2e ✅ Succeeded 8m 24s View ↗
nx affected -t lint,test,build -c ci ✅ Succeeded 1m 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 8s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-23 22:13:38 UTC

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves Payload CMS preview safety/behavior, strengthens multi-tenant media isolation (including S3 key prefixing), fixes post image rendering (embedded image blocks + hero images), and hardens the DB migration test harness readiness check.

Changes:

  • Updates preview handling (open-redirect prevention, draft-mode behavior) and adds middleware to clear stale draft cookies after logout/session expiry.
  • Implements tenant-aware media storage (tenant filename prefixing + prefix field) and updates rendering/UI types to support clean display (filenameWithoutPrefix) and correct URL joining.
  • Fixes CMS renderer image support (register image block converter, use ImageBlock for hero images) and adjusts migration-test Postgres readiness polling to use host TCP.

Reviewed changes

Copilot reviewed 15 out of 17 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tools/db-tools/lib/test-migration.ts Polls Postgres readiness via host TCP psql instead of container socket checks
package.json Bumps Payload and related plugin versions to ~3.71.0
pnpm-lock.yaml Locks updated Payload ecosystem dependencies and transitive updates
packages/nx-payload/src/utils/versions.ts Aligns workspace-wide Payload ESM version to ~3.71.0
apps/web/package.json Updates @payloadcms/richtext-lexical to ~3.71.0
apps/cms/src/app/api/preview/route.ts Tightens preview redirect validation and enables draft mode for authenticated admins
apps/cms/src/middleware.ts Clears stale __prerender_bypass when payload-token is missing
apps/cms/src/collections/media/media.collection.ts Adds tenant-based filename prefixing + prefix/filenameWithoutPrefix fields and compound uniqueness
apps/cms/src/migrations/index.ts Registers new migration 20260422_222457_cod_383
apps/cms/src/migrations/20260422_222457_cod_383.ts Adds media prefix + filename_without_prefix columns and index changes
libs/shared/util/payload-types/src/lib/payload-types.ts Extends generated types with prefix and filenameWithoutPrefix
libs/shared/ui/cms-renderer/src/lib/render/RenderPost.tsx Renders hero image via ImageBlock
libs/shared/ui/cms-renderer/src/lib/blocks/RichText.tsx Registers image block converter so embedded images render
libs/shared/ui/cms-renderer/src/lib/blocks/ImageBlock.tsx Fixes URL joining and supports hiding captions for hero usage
libs/shared/ui/cms-renderer/src/lib/blocks/MediaBlock.tsx Fixes URL joining for media rendering
libs/shared/ui/cms-renderer/src/lib/blocks/FileAreaBlock.tsx Uses filenameWithoutPrefix for display in file areas
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/cms/src/migrations/20260422_222457_cod_383.ts
Comment thread apps/cms/src/migrations/20260422_222457_cod_383.ts
Comment thread apps/cms/src/collections/media/media.collection.ts
Comment thread apps/cms/src/collections/media/media.collection.ts
Comment thread libs/shared/ui/cms-renderer/src/lib/blocks/FileAreaBlock.tsx Outdated
Comment thread libs/shared/ui/cms-renderer/src/lib/blocks/FileAreaBlock.tsx Outdated
@codeware-actions
Copy link
Copy Markdown

✨ Your pull request projects are ready for preview

Project App name Preview
cms (_default) cdwr-cms-pr-420 https://cdwr-cms-pr-420.fly.dev
cms (demo) cdwr-cms-pr-420-demo https://cdwr-cms-pr-420-demo.fly.dev
web (demo) cdwr-web-pr-420-demo https://cdwr-web-pr-420-demo.fly.dev

@hakalb hakalb added the preview-deploy PR Trigger: run continuous preview deployments label Apr 23, 2026
@hakalb hakalb force-pushed the fix/cms-preview-route-redirect branch from 6ddb812 to 854fa56 Compare April 23, 2026 20:38
@codeware-actions
Copy link
Copy Markdown

✨ Your pull request projects are ready for preview

Project App name Preview
cms (_default) cdwr-cms-pr-420 https://cdwr-cms-pr-420.fly.dev
cms (demo) cdwr-cms-pr-420-demo https://cdwr-cms-pr-420-demo.fly.dev
web (demo) cdwr-web-pr-420-demo https://cdwr-web-pr-420-demo.fly.dev

@hakalb hakalb force-pushed the fix/cms-preview-route-redirect branch from 854fa56 to 923435a Compare April 23, 2026 21:37
@hakalb hakalb removed the preview-deploy PR Trigger: run continuous preview deployments label Apr 23, 2026
@hakalb hakalb force-pushed the fix/cms-preview-route-redirect branch from 923435a to f017db3 Compare April 23, 2026 21:49
@hakalb hakalb enabled auto-merge April 23, 2026 22:05
@hakalb hakalb added this pull request to the merge queue Apr 23, 2026
@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 26.31579% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.18%. Comparing base (88ae07c) to head (f017db3).

Files with missing lines Patch % Lines
...ared/ui/cms-renderer/src/lib/blocks/ImageBlock.tsx 12.50% 7 Missing ⚠️
...d/ui/cms-renderer/src/lib/blocks/FileAreaBlock.tsx 0.00% 4 Missing ⚠️
...ared/ui/cms-renderer/src/lib/blocks/MediaBlock.tsx 0.00% 1 Missing ⚠️
...shared/ui/cms-renderer/src/lib/blocks/RichText.tsx 50.00% 1 Missing ⚠️
...ared/ui/cms-renderer/src/lib/render/RenderPost.tsx 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #420       +/-   ##
===========================================
+ Coverage   43.77%   64.18%   +20.41%     
===========================================
  Files         128      207       +79     
  Lines        1558     5350     +3792     
  Branches      334      734      +400     
===========================================
+ Hits          682     3434     +2752     
- Misses        831     1866     +1035     
- Partials       45       50        +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Merged via the queue into main with commit 04d1c7a Apr 23, 2026
11 checks passed
@hakalb hakalb deleted the fix/cms-preview-route-redirect branch April 23, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants