Skip to content

fix(homepage): guard blog category load#452

Open
OleksandrMrn wants to merge 1 commit into
DevLoversTeam:developfrom
OleksandrMrn:om/fix/homepage/db-fallback
Open

fix(homepage): guard blog category load#452
OleksandrMrn wants to merge 1 commit into
DevLoversTeam:developfrom
OleksandrMrn:om/fix/homepage/db-fallback

Conversation

@OleksandrMrn

@OleksandrMrn OleksandrMrn commented Jun 29, 2026

Copy link
Copy Markdown

Description

Prevents optional blog category navigation data from crashing the localized homepage layout when database access fails.

Also normalizes NEXT_PUBLIC_SITE_URL before building homepage canonical and alternate metadata links, avoiding double slashes like //uk.


Related Issue

Issue: N/A


Changes

  • Guard optional blog category loading in the locale layout
  • Return an empty category list when blog categories cannot be loaded
  • Leave locale message loading unchanged
  • Normalize homepage metadata URLs when NEXT_PUBLIC_SITE_URL has a trailing slash

Database Changes (if applicable)

  • Schema migration required
  • Seed data updated
  • Breaking changes to existing queries
  • Transaction-safe migration
  • Migration tested locally on Neon

N/A, no database schema or query changes.


How Has This Been Tested?

  • Tested locally
  • Verified in development environment
  • Checked responsive layout (if UI-related)
  • Tested accessibility (keyboard / screen reader)

Tested locally with the Next.js dev server:

  • /uk loads successfully
  • /en loads successfully
  • Verified the homepage no longer returns 500 when blog category loading fails
  • Ran lint/checks for the changed files

Screenshots (if applicable)

N/A


Checklist

Before submitting

  • Code has been self-reviewed
  • No TypeScript or console errors
  • Code follows project conventions
  • Scope is limited to this feature/fix
  • No unrelated refactors included
  • English used in code, commits, and docs
  • No new dependencies added
  • Database migration tested locally (if applicable)
  • GitHub Projects card moved to In Review

Reviewers

Summary by CodeRabbit

  • Bug Fixes
    • Improved site URL handling so generated links are consistently formatted, avoiding issues with trailing slashes.
    • Made blog category loading more resilient by falling back gracefully if category data can’t be retrieved, helping pages continue to load smoothly.

- prevent optional blog category navigation data from crashing the localized homepage layout when database access fails
- normalize the homepage site URL before building canonical and alternate metadata links
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@OleksandrMrn is attempting to deploy a commit to the DevLovers Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6c568391-531e-4e24-89e1-246bb9451773

📥 Commits

Reviewing files that changed from the base of the PR and between f8ffed5 and 2b54f88.

📒 Files selected for processing (2)
  • frontend/app/[locale]/layout.tsx
  • frontend/app/[locale]/page.tsx

📝 Walkthrough

Walkthrough

The locale layout's blog-category loading is refactored into a local getLayoutBlogCategories helper that uses a dynamic import and catches errors by logging and returning an empty array. Separately, generateMetadata normalizes NEXT_PUBLIC_SITE_URL by stripping any trailing slash before constructing URLs.

Layout resilience improvements

Layer / File(s) Summary
Blog categories dynamic import with error fallback
frontend/app/[locale]/layout.tsx
Adds BlogCategory type and getLayoutBlogCategories(locale) helper with dynamic import, success return, and [] fallback on error. LocaleLayout's Promise.all is updated to call this helper instead of the prior direct cached-query reference.
siteUrl trailing-slash normalization
frontend/app/[locale]/page.tsx
generateMetadata now strips a trailing / from NEXT_PUBLIC_SITE_URL (or its fallback) before assigning siteUrl, affecting all derived URLs such as canonicalUrl.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • DevLoversTeam/devlovers.net#422: Directly modified the same Promise.all blog-categories loading in layout.tsx, hardcoding an empty array — this PR reintroduces the fetch via the new helper.

Suggested reviewers

  • AM1007
  • ViktorSvertoka
  • LesiaUKR

Poem

🐇 A trailing slash once caused a fright,
the blog fetch crashed and hid from sight.
With dynamic import, wrapped up tight,
an empty array guards the night.
Now URLs are trimmed just right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main homepage fix: guarding blog category loading to prevent crashes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant