Fix admin studio article preview always showing "moved" error

ArticlePage and NewsGrid called useContent() directly, bypassing the
draft content SiteApp resolves for admin previews. Since /admin is
rendered outside ContentProvider, this always returned an empty post
list, so every article in the studio looked unpublished.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-13 12:18:13 +05:00
co-authored by Claude Sonnet 5
parent 63a36e0dca
commit 410463e0ed
3 changed files with 34 additions and 9 deletions
+6 -3
View File
@@ -163,11 +163,11 @@ export default function SiteApp({ pageId = 'p1', articleSlug, previewContent, su
{mounts['mobile-sdk-demo-mount'] && createPortal(<ThreatDemosSlider embedded />, mounts['mobile-sdk-demo-mount'])} {mounts['mobile-sdk-demo-mount'] && createPortal(<ThreatDemosSlider embedded />, mounts['mobile-sdk-demo-mount'])}
{mounts['news-grid-mount'] && createPortal(<NewsGrid />, mounts['news-grid-mount'])} {mounts['news-grid-mount'] && createPortal(<NewsGrid content={content} />, mounts['news-grid-mount'])}
{mounts['home-news-mount'] && {mounts['home-news-mount'] &&
createPortal( createPortal(
<NewsGrid limit={3} showFilters={false} heading="Latest news and insights" />, <NewsGrid limit={3} showFilters={false} heading="Latest news and insights" content={content} />,
mounts['home-news-mount'], mounts['home-news-mount'],
)} )}
@@ -190,7 +190,10 @@ export default function SiteApp({ pageId = 'p1', articleSlug, previewContent, su
{articleSlug && {articleSlug &&
mounts['pg-article'] && mounts['pg-article'] &&
createPortal(<ArticlePage slug={articleSlug} suppressMeta={suppressMeta} />, mounts['pg-article'])} createPortal(
<ArticlePage slug={articleSlug} suppressMeta={suppressMeta} content={content} />,
mounts['pg-article'],
)}
</> </>
) )
} }
+13 -3
View File
@@ -3,15 +3,25 @@ import { useNavigate } from 'react-router-dom'
import { formatPostDate, publishedPosts, useContent } from '../../cms/store' import { formatPostDate, publishedPosts, useContent } from '../../cms/store'
import { applyJsonLd, applyMeta, articleJsonLd } from '../../cms/seo' import { applyJsonLd, applyMeta, articleJsonLd } from '../../cms/seo'
import { categoryMeta, splitAuthor } from './NewsGrid' import { categoryMeta, splitAuthor } from './NewsGrid'
import type { Post } from '../../cms/types' import type { Post, SiteContent } from '../../cms/types'
/** /**
* A single article at /blog/<slug>. Rendered into the #pg-article container inside * A single article at /blog/<slug>. Rendered into the #pg-article container inside
* the site markup, so it inherits the real nav, footer and enquiry modal — and the * the site markup, so it inherits the real nav, footer and enquiry modal — and the
* white-section rule that makes the body copy readable. * white-section rule that makes the body copy readable.
*/ */
export default function ArticlePage({ slug, suppressMeta = false }: { slug: string; suppressMeta?: boolean }) { export default function ArticlePage({
const content = useContent() slug,
suppressMeta = false,
content: contentProp,
}: {
slug: string
suppressMeta?: boolean
/** Admin preview: use the editor's draft rather than the published context. */
content?: SiteContent
}) {
const publishedContent = useContent()
const content = contentProp || publishedContent
const navigate = useNavigate() const navigate = useNavigate()
// Drafts are reachable by direct link so they can be reviewed before going live, // Drafts are reachable by direct link so they can be reviewed before going live,
+15 -3
View File
@@ -1,6 +1,6 @@
import { useMemo, useState } from 'react' import { useMemo, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { POST_CATEGORIES, type Post, type PostCategory } from '../../cms/types' import { POST_CATEGORIES, type Post, type PostCategory, type SiteContent } from '../../cms/types'
import { formatPostDate, publishedPosts, useContent } from '../../cms/store' import { formatPostDate, publishedPosts, useContent } from '../../cms/store'
export const categoryMeta = (id: string) => POST_CATEGORIES.find((c) => c.id === id) || POST_CATEGORIES[0] export const categoryMeta = (id: string) => POST_CATEGORIES.find((c) => c.id === id) || POST_CATEGORIES[0]
@@ -48,8 +48,20 @@ function Card({ post, onOpen }: { post: Post; onOpen: (post: Post) => void }) {
* The newsroom grid (/news) and the home page's latest-three strip. Both read the * The newsroom grid (/news) and the home page's latest-three strip. Both read the
* same CMS post library, so publishing an article puts it everywhere it belongs. * same CMS post library, so publishing an article puts it everywhere it belongs.
*/ */
export default function NewsGrid({ limit, showFilters = true, heading }: { limit?: number; showFilters?: boolean; heading?: string }) { export default function NewsGrid({
const content = useContent() limit,
showFilters = true,
heading,
content: contentProp,
}: {
limit?: number
showFilters?: boolean
heading?: string
/** Admin preview: use the editor's draft rather than the published context. */
content?: SiteContent
}) {
const publishedContent = useContent()
const content = contentProp || publishedContent
const navigate = useNavigate() const navigate = useNavigate()
const [filter, setFilter] = useState<PostCategory | 'all'>('all') const [filter, setFilter] = useState<PostCategory | 'all'>('all')