Skip to content

Fix white screen issue when loading category pages directly - #34

Draft
therealpaulgg with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-33
Draft

Fix white screen issue when loading category pages directly#34
therealpaulgg with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-33

Conversation

Copilot AI commented Jun 10, 2025

Copy link
Copy Markdown
Contributor

This PR fixes the white screen issue that occurs when users navigate directly to a category page (e.g., /category/cooking) instead of navigating from the home page.

Problem

When loading a category page directly, users would see a white screen due to unhandled errors in the data loading process. The issue only occurred on direct navigation - navigating from the home page worked correctly.

Root Cause

The issue was caused by lack of error handling in two critical places:

  1. Server endpoint (src/routes/category/[slug].json/+server.ts): No error handling for file system operations or markdown processing failures
  2. Page loader (src/routes/category/[slug]/+page.ts): No error handling for fetch request failures

Any errors during data loading would cause the entire page load to fail, resulting in a white screen instead of graceful fallback behavior.

Solution

Added comprehensive error handling to both components:

Server Endpoint Changes

  • Wrapped directory reading and file processing in try-catch blocks
  • Individual error handling for each recipe file to prevent one bad file from breaking the entire category
  • Returns empty array [] as fallback when category directory doesn't exist or can't be read
  • Logs specific error messages for debugging

Page Loader Changes

  • Added try-catch around the fetch request and JSON parsing
  • Returns { recipes: [], slug } as fallback when API request fails
  • Preserves the slug parameter so the page can still display the category name

Testing

  • Verified build process completes successfully
  • Tested with intentionally malformed recipe files to confirm error handling works
  • Confirmed that pages now show "No recipes found" message instead of white screen when errors occur
  • Static site generation works correctly and pre-renders all valid category pages

The fix ensures that category pages always load gracefully, even when there are underlying data issues, while maintaining full functionality for valid categories.

Fixes #33.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits June 10, 2025 07:02
Co-authored-by: therealpaulgg <21159486+therealpaulgg@users.noreply.github.com>
Co-authored-by: therealpaulgg <21159486+therealpaulgg@users.noreply.github.com>
Copilot AI changed the title [WIP] White screen when loading category page Fix white screen issue when loading category pages directly Jun 10, 2025
Copilot AI requested a review from therealpaulgg June 10, 2025 07:10
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.

White screen when loading category page

2 participants