Skip to content

fix(enhancement): fixed the authorPage fallback by adding a precautiv…#319

Open
devlopharsh wants to merge 5 commits intokeploy:mainfrom
devlopharsh:fix/fixing-authorPage-fallback-build#3723
Open

fix(enhancement): fixed the authorPage fallback by adding a precautiv…#319
devlopharsh wants to merge 5 commits intokeploy:mainfrom
devlopharsh:fix/fixing-authorPage-fallback-build#3723

Conversation

@devlopharsh
Copy link
Copy Markdown

Related Tickets & Documents

Fixes: #3723

Description

  • Issue : When a new author slug was requested and getStaticPaths used fallback: true, the page rendered before data was ready and showed a false “No posts found” message.

  • Solution : I have fixed that by adding a fallback loading state and then improved the “no posts” UI/redirect flow. This would improve the UX of the website .

Changes

  • Added a safe fallback/loading flow so author pages don’t show a false “No posts found” during ISR build.
  • Improved author matching to try ppmaAuthorName first, then fall back to WordPress.
  • Replaced the plain “No posts found” text with a proper empty‑state UI and a 10‑second redirect to /authors.

Type of Change

  • Chore (maintenance, refactoring, tooling updates)
  • Bug fix (non-breaking change that fixes an issue)
  • New feature (change that adds functionality)
  • Breaking Change (may require updates in existing code)
  • UI improvement (visual or design changes)
  • Performance improvement (optimization or efficiency enhancements)
  • Documentation update (changes to README, guides, etc.)
  • CI (updates to continuous integration workflows)
  • Revert (undo a previous commit or merge)

Testing and Demo

  • Build the Application Successfully.
  • Before Changes :
Screen.Recording.2026-02-05.011331.mp4
  • After Changes :
Screen.Recording.2026-02-06.000842.mp4
Screenshot 2026-02-06 002757

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added corresponding tests
  • I have run the build command to ensure there are no build errors
  • My changes have been tested across relevant browsers/devices
  • For UI changes, I've included visual evidence of my changes

@devlopharsh
Copy link
Copy Markdown
Author

@Achanandhi-M @amaan-bhati , Please have a review over the solution for the issue in the blog website , please let me know for further correction if needed ,
Thank you ,

@dhananjay6561
Copy link
Copy Markdown
Member

Hi @devlopharsh
Thanks for the contribution and for working on the authorPage fallback fix.

While reviewing the PR locally, the build fails during static page generation for the /authors/[slug] route. It looks like there’s an issue when the AuthorPage is being rendered during the build process, which causes the export step to fail.

Could you please take a look at this and ensure the fallback logic properly handles cases where the author data might be undefined or missing during build time?

Once the build passes successfully, we can proceed further with the PR. Thanks again for the effort!

@devlopharsh
Copy link
Copy Markdown
Author

@dhananjay6561 okay sir ,
let me have a look over it !! Thank you !

@dhananjay6561
Copy link
Copy Markdown
Member

@dhananjay6561 okay sir , let me have a look over it !! Thank you !

sure!

Signed-off-by: developharsh <harsh237hk@gmail.com>
@devlopharsh
Copy link
Copy Markdown
Author

@dhananjay6561 , i have pushed the corrected code in my branch , the issue was becuase of minor variable accessing , corrected my code and pushed again !!

@dhananjay6561 dhananjay6561 requested a review from Copilot April 6, 2026 12:07
@dhananjay6561
Copy link
Copy Markdown
Member

Hey @devlopharsh 👋 — thanks for putting this PR together, we appreciate the effort!

We've gone ahead and requested a Copilot review on this. Here's some context from the reviewer:

Remove 'use client' (Pages Router). Does /images/error404.png exist? getStaticProps now always calls getAllPosts — perf concern.

Once you've had a chance to go through the comments, please address the feedback and resolve the threads — and we'll get this across the line. Feel free to ask if anything's unclear. Happy coding! 💙

Copy link
Copy Markdown
Contributor

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

Improves the UX for author profile pages generated via getStaticPaths with fallback: true, preventing a misleading “No posts found” flash during ISR builds and providing a richer empty-state experience when an author truly has no posts.

Changes:

  • Adds a fallback/loading UI wrapper (AuthorEmptyState) with timed redirect for empty author pages.
  • Improves author name resolution (prefers ppmaAuthorName, falls back to WordPress author.node.name).
  • Adjusts author-page data fetching to attempt matching via getAllPosts() before other strategies.

Reviewed changes

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

File Description
pages/authors/[slug].tsx Uses the new empty-state wrapper and updates author-name/metadata + matching logic in getStaticProps.
components/postByAuthorMapping.tsx Adds a guard for empty filteredPosts and makes author name resolution more resilient.
components/author-empty-state.tsx Introduces a client-side empty/loading wrapper with redirect countdown and image support.
Comments suppressed due to low confidence (1)

pages/authors/[slug].tsx:39

  • When authorName is unavailable (fallback render or noPosts), the breadcrumb structured data uses name: "Author" and builds the URL with an empty slug (/authors/). That produces incorrect structured data for the actual /authors/[slug] page. Consider omitting the final crumb until authorName is known, or using the requested slug for the crumb URL (and a stable display name) during fallback/empty states.
        structuredData={[
          getBreadcrumbListSchema([
            { name: "Home", url: SITE_URL },
            { name: "Authors", url: `${SITE_URL}/authors` },
            {
              name: authorName || "Author",
              url: `${SITE_URL}/authors/${sanitizeAuthorSlug(authorName || "")}`,
            },
          ]),

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

Comment thread pages/authors/[slug].tsx
Comment on lines +140 to 180
const allEdges = allPostsResponse?.edges || [];

// 1) Try matching custom author field first (ppmaAuthorName)
filteredPosts = allEdges.filter(({ node }) => {
const candidateName = node?.ppmaAuthorName;
if (!candidateName || Array.isArray(candidateName)) {
return false;
}
return sanitizeAuthorSlug(candidateName) === sanitizeAuthorSlug(slugParam);
});

// 2) If no match, try WordPress author name
if (!filteredPosts.length) {
try {
const allPostsResponse = await getAllPosts();
filteredPosts =
allPostsResponse?.edges?.filter(({ node }) => {
const candidateName = node?.ppmaAuthorName;
if (!candidateName || Array.isArray(candidateName)) {
return false;
}
return sanitizeAuthorSlug(candidateName) === sanitizeAuthorSlug(slugParam);
}) || [];
} catch (error) {
console.error("authors/[slug] fallback to getAllPosts failed:", error);
filteredPosts = [];
filteredPosts = allEdges.filter(({ node }) => {
const authorName = node?.author?.node?.name;
if (!authorName || Array.isArray(authorName)) {
return false;
}
return sanitizeAuthorSlug(authorName) === sanitizeAuthorSlug(slugParam);
});
}

// 3) If still no match and allPosts failed, fall back to direct author query
if (!filteredPosts.length && !allEdges.length) {
for (const candidate of Array.from(candidateAuthorNames)) {
if (!candidate) continue;
try {
const postsResponse = await getPostsByAuthorName(candidate);
const edges = postsResponse?.edges || [];
if (edges.length > 0) {
filteredPosts = edges;
break;
}
} catch (error) {
console.error(
`authors/[slug] failed to fetch posts for candidate "${candidate}":`,
error,
);
}
}
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The direct author lookup fallback only runs when allEdges is empty. Since getAllPosts() currently only returns the first page of posts (its GraphQL query doesn’t fetch pageInfo, so pagination stops after the first request), authors whose posts aren’t in that first batch will incorrectly render as noPosts. Consider running the getPostsByAuthorName candidate loop whenever there’s no match from allEdges (not only when allEdges.length === 0), or fixing getAllPosts() pagination and relying on it consistently.

Copilot uses AI. Check for mistakes.
Comment thread pages/authors/[slug].tsx
Comment on lines +17 to +30
const noPosts = filteredPosts.length === 0;
const authorName =
filteredPosts?.[0]?.node?.ppmaAuthorName ??
filteredPosts?.[0]?.node?.author?.node?.name;

return (
<div className="bg-accent-1">
<Layout
preview={preview}
featuredImage={HOME_OG_IMAGE_URL}
Title={`${authorName} Page`}
Description={`Posts by ${authorName}`}
Title={noPosts ? "Author Not Found" : `${authorName} Page`}
Description={
noPosts ? "No posts found for this author" : `Posts by ${authorName}`
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

During fallback: true rendering, filteredPosts is still empty so noPosts becomes true and the page metadata is set to "Author Not Found" even though the UI shows a loading state via router.isFallback. This can flash an incorrect title/description to users and can be captured in previews. Consider checking router.isFallback in AuthorPage (via useRouter) and using a loading title/description (or deferring the "not found" metadata until after fallback resolves).

Copilot uses AI. Check for mistakes.
}

return (
<div className="w-full max-w-5xl mx-auto text-center md:text-left py-16 px-6 bg-white rounded-2xl shadow-sm border border-orange-100 flex flex-col md:flex-row md:justify-between items-center mb-15">
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

mb-15 isn’t a default Tailwind spacing utility and there’s no custom 15 spacing configured in tailwind.config.js, so this margin class won’t apply. Use an existing spacing step (e.g. mb-14/mb-16) or an arbitrary value (e.g. mb-[60px]) if you need a specific size.

Suggested change
<div className="w-full max-w-5xl mx-auto text-center md:text-left py-16 px-6 bg-white rounded-2xl shadow-sm border border-orange-100 flex flex-col md:flex-row md:justify-between items-center mb-15">
<div className="w-full max-w-5xl mx-auto text-center md:text-left py-16 px-6 bg-white rounded-2xl shadow-sm border border-orange-100 flex flex-col md:flex-row md:justify-between items-center mb-[60px]">

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +30
if (imagePath.startsWith("/") && router.basePath) {
return `${router.basePath}${imagePath}`;
}
return imagePath;
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

imageSrc unconditionally prefixes router.basePath for any absolute path. In this codebase, public image paths are often already written with the /blog/... prefix (e.g. /blog/images/error404.png, /blog/images/author.png), so passing a pre-prefixed path would become /blog/blog/.... Consider guarding for imagePath.startsWith(router.basePath + '/') before prefixing, or standardizing the expected imagePath format for this component.

Suggested change
if (imagePath.startsWith("/") && router.basePath) {
return `${router.basePath}${imagePath}`;
}
return imagePath;
if (!imagePath.startsWith("/") || !router.basePath) {
return imagePath;
}
if (
imagePath === router.basePath ||
imagePath.startsWith(`${router.basePath}/`)
) {
return imagePath;
}
return `${router.basePath}${imagePath}`;

Copilot uses AI. Check for mistakes.
<div className="w-full max-w-5xl mx-auto text-center md:text-left py-16 px-6 bg-white rounded-2xl shadow-sm border border-orange-100 flex flex-col md:flex-row md:justify-between items-center mb-15">
<div>
<h1 className="text-3xl md:text-3xl font-bold text-orange-600 ">
OOPs!! No post found for the Author
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

Spelling/grammar in the empty-state heading: "OOPs!! No post found for the Author" should be corrected (e.g., "Oops! No posts found for this author").

Suggested change
OOPs!! No post found for the Author
Oops! No posts found for this author

Copilot uses AI. Check for mistakes.
</div>
</div>
<div>
<Image src={imageSrc} alt="errorImage" width={300} height={400} />
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The image alt text "errorImage" isn’t descriptive for screen readers. Use an alt text that describes the content/purpose (e.g. “404 illustration” / “No posts found illustration”), or empty alt ("") if it’s purely decorative.

Suggested change
<Image src={imageSrc} alt="errorImage" width={300} height={400} />
<Image
src={imageSrc}
alt="No posts found for this author illustration"
width={300}
height={400}
/>

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Author pages briefly show “No posts found” during fallback build

3 participants