Skip to content

fix: hoist useBaseUrl calls to follow Rules of Hooks - #724

Open
Anshumancanrock wants to merge 1 commit into
Project-HAMi:masterfrom
Anshumancanrock:fix/useBaseUrl-hooks
Open

fix: hoist useBaseUrl calls to follow Rules of Hooks#724
Anshumancanrock wants to merge 1 commit into
Project-HAMi:masterfrom
Anshumancanrock:fix/useBaseUrl-hooks

Conversation

@Anshumancanrock

@Anshumancanrock Anshumancanrock commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

useBaseUrl is a React hook, but we were calling it inside .map()s, conditionals, and after an early return in Footer. It's against the Rules of Hooks and will blow up if that data becomes conditional.

Fix: use useBaseUrlUtils() / hoist the hook calls to the top level.

Which issue(s) this PR fixes:

Fixes #723

Checklist:

  • npm run lint and npm run format:check pass
  • npm run build succeeds for both en and zh
  • Chinese translation updated if English docs changed (or noted why not) — N/A, JS only
  • Commits are signed off (git commit -s)

Summary by CodeRabbit

  • Bug Fixes
    • Improved URL handling across homepage, case studies, blog covers, and footer links.
    • Ensured images and navigation links resolve correctly in different site paths and locales.
    • Improved footer rendering consistency when footer configuration is unavailable.

Signed-off-by: anshumancanrock <anshu.1239.as@gmail.com>
@hami-robot hami-robot Bot added kind/bug Something isn't working dco-signoff: yes labels Aug 5, 2026
@hami-robot
hami-robot Bot requested a review from archlitchi August 5, 2026 06:09
@hami-robot

hami-robot Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Anshumancanrock
Once this PR has been reviewed and has the lgtm label, please assign wawa0210 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot
hami-robot Bot requested a review from rootsongjc August 5, 2026 06:09
@netlify

netlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for project-hami ready!

Name Link
🔨 Latest commit 11febfb
🔍 Latest deploy log https://app.netlify.com/projects/project-hami/deploys/6a72d3a38403190008613236
😎 Deploy Preview https://deploy-preview-724--project-hami.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hami-robot hami-robot Bot added the size/M label Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

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 Plus

Run ID: efaad86f-149b-4511-a332-1cbd9f509dcd

📥 Commits

Reviewing files that changed from the base of the PR and between c0e0f77 and 11febfb.

📒 Files selected for processing (4)
  • src/pages/case-studies.js
  • src/pages/index.js
  • src/theme/BlogPostItem/Header/index.js
  • src/theme/Footer/index.js

📝 Walkthrough

Walkthrough

The change replaces conditional or repeated useBaseUrl calls with useBaseUrlUtils and withBaseUrl. It also moves footer initialization before the early return and reuses a computed blog cover URL.

Changes

URL resolution and hook consistency

Layer / File(s) Summary
Page URL resolution
src/pages/case-studies.js, src/pages/index.js
Case-study logos and home-page assets and links now use withBaseUrl.
Blog cover URL initialization
src/theme/BlogPostItem/Header/index.js
The cover URL is computed once and reused by the cover image.
Footer hook ordering
src/theme/Footer/index.js
Locale and asset URLs are initialized before the footer null check. Duplicate initialization was removed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: rootsongjc

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: hoisting useBaseUrl calls to comply with React Rules of Hooks.
Linked Issues check ✅ Passed The changes hoist or replace all useBaseUrl call sites identified in issue #723, including mapped, conditional, and post-return calls.
Out of Scope Changes check ✅ Passed All reported changes directly support issue #723 by correcting hook usage and preserving URL resolution behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useBaseUrl breaks Rules of Hooks in a few components

1 participant