Skip to content

fix: scope changelog plugin state per loadContent and derive figure locale from pathname (fixes #699) - #700

Open
bhuvan-somisetty wants to merge 2 commits into
Project-HAMi:masterfrom
bhuvan-somisetty:fix/699-changelog-global-state-and-figure-locale-desync
Open

fix: scope changelog plugin state per loadContent and derive figure locale from pathname (fixes #699)#700
bhuvan-somisetty wants to merge 2 commits into
Project-HAMi:masterfrom
bhuvan-somisetty:fix/699-changelog-global-state-and-figure-locale-desync

Conversation

@bhuvan-somisetty

@bhuvan-somisetty bhuvan-somisetty commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

This PR resolves build-time state pollution in the changelog generator plugin and client-side race conditions / anchor detachment in figure caption generation:

  1. Changelog plugin state scoping (src/plugins/changelog/index.js):

    • publishTimes (Set) and authorsMap (Object) were defined as module-level global singletons. During production multi-locale builds (npm run build), Docusaurus runs loadContent() sequentially for en then zh in the same Node process. Because publishTimes was never reset between locale runs, the zh pass detected all timestamps from en as existing collisions. The dedup loop (while (publishTimes.has(...)) hour -= 1) decremented release hours for every entry, shifting Chinese changelog dates, RSS/Atom feed timestamps, and post sorting backward relative to English.
    • Fix: Moved publishTimes and authorsMap instantiation inside loadContent() and passed them down to processSection. Each build pass now starts with a clean slate, ensuring deterministic and matching timestamps across all locales.
  2. Client-side figure caption race condition & anchor preservation (src/client/imageFigureNumber.js):

    • onRouteDidUpdate scheduled triple setTimeout timers (100ms, 500ms, 1000ms) and read document.documentElement.lang to decide between Figure and caption prefixes. Because Docusaurus updates <html lang="..."> asynchronously after route transitions complete, early timeout callbacks read stale lang values, outputting English captions on Chinese pages or vice versa. Additionally, root doc paths (/docs or /zh/docs) were missed by strict regex, and wrapping unlinked images detached <img> elements from parent <a> link tags.
    • Fix: Derived locale directly from location.pathname (checking for /zh/), expanded route regex to match root doc routes /(?:^|\/)(?:blog|docs)(?:$|\/)/, preserved parent <a> tags inside <figure> wrappers for linked images, replaced triple setTimeout calls with a single requestAnimationFrame tick, and ensured <figcaption> text is always updated dynamically.

Which issue(s) this PR fixes:

Fixes #699

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 (N/A — code bug fix)
  • Commits are signed off (git commit -s)

… locale from pathname

changelog-plugin: publishTimes and authorsMap were declared as module-level globals. During a multi-locale build Docusaurus runs loadContent() sequentially for each locale (en, zh) within the same Node process. As a result the zh pass found all en timestamps already in publishTimes and the dedup loop decremented every hour offset by the number of en releases, causing zh changelog post dates and RSS/Atom timestamps to shift backward relative to en. Fix: declare publishTimes and authorsMap inside loadContent() so every locale pass starts with empty state.

imageFigureNumber.js: the client module fired three staggered setTimeouts and read document.documentElement.lang to choose the Figure/图 prefix. The html[lang] attribute is updated by Docusaurus after the route transition completes; early timeout callbacks read the previous locale value, producing English captions on Chinese pages or vice versa. Overlapping timeouts without idempotency guards also created duplicate figcaption elements under fast navigation. Fix: replace triple setTimeout with a single requestAnimationFrame (Docusaurus has already committed the incoming page to the DOM by the time onRouteDidUpdate fires), derive locale from location.pathname, and always overwrite the figcaption text rather than skipping already-annotated figures.

Fixes Project-HAMi#699

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
@hami-robot

hami-robot Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bhuvan-somisetty
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

@netlify

netlify Bot commented Aug 2, 2026

Copy link
Copy Markdown

Deploy Preview for project-hami ready!

Name Link
🔨 Latest commit 176e8ac
🔍 Latest deploy log https://app.netlify.com/projects/project-hami/deploys/6a6f34c10ba5cf0008d0e130
😎 Deploy Preview https://deploy-preview-700--project-hami.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@hami-robot hami-robot Bot added the size/L label Aug 2, 2026
@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

Hey @rootsongjc @mesutoezdil — submitted a fix for #699. This addresses the build-time changelog global state leak across locales as well as the client-side figure caption race condition during SPA navigation. Ready for review when you have a moment!

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@bhuvan-somisetty, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 36e65d2b-65fa-4f02-97d9-df9dea771642

📥 Commits

Reviewing files that changed from the base of the PR and between ad4d08f and 176e8ac.

📒 Files selected for processing (1)
  • src/client/imageFigureNumber.js
📝 Walkthrough

Walkthrough

The PR updates client-side figure captions to use pathname-derived locales and single-frame route updates. It also scopes changelog timestamps and author maps to each content-loading invocation.

Changes

Figure caption locale handling

Layer / File(s) Summary
Route-based figure caption updates
src/client/imageFigureNumber.js
Route updates derive the locale from the pathname and schedule one requestAnimationFrame callback. Figure captions are reused or created and always receive the current number, locale prefix, and image alt text.

Changelog build state isolation

Layer / File(s) Summary
Invocation-scoped changelog state
src/plugins/changelog/index.js
loadContent creates fresh publish-time and author accumulators and passes them to each section processor. The title replacement uses equivalent double-quoted syntax.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • Project-HAMi/website#692: Both changes modify route-driven figure caption handling in src/client/imageFigureNumber.js.

Suggested labels: kind/bug

Suggested reviewers: rootsongjc

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR addresses changelog state and figure caption defects, but it does not update announcementBar.content as required by issue #699. Add valid default English HTML to announcementBar.content, then verify the linked issue acceptance criteria and npm run check:all.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changes are limited to changelog state isolation and figure caption locale handling, which directly match issue #699 objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes both main fixes: scoped changelog state and pathname-based figure locale handling.
✨ 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.

@coderabbitai coderabbitai Bot added the kind/bug Something isn't working label Aug 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/client/imageFigureNumber.js`:
- Around line 63-69: Update the figure-creation logic around the
closest("figure") check to detect when the image is wrapped in an anchor and
move that anchor into the new figure instead of moving only the img. Preserve
the existing behavior for unlinked images and keep the image inside its link so
it remains clickable.
- Around line 18-21: Update the route filter in onRouteDidUpdate to recognize
root document routes such as /docs and /zh/docs, while preserving blog matching.
Match blog and docs as path segments with an optional trailing slash so nested
pages and localized document roots continue to be handled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e4432efa-a5be-4a5d-bb4d-2c781c7218c1

📥 Commits

Reviewing files that changed from the base of the PR and between a0b4368 and ad4d08f.

📒 Files selected for processing (2)
  • src/client/imageFigureNumber.js
  • src/plugins/changelog/index.js

Comment thread src/client/imageFigureNumber.js
Comment thread src/client/imageFigureNumber.js Outdated
…d images

Update route regex in onRouteDidUpdate to match root document paths such as /docs and /zh/docs. Also detect when an image is wrapped inside an anchor tag and move the anchor into the figure element so image hyperlinks remain functional.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

Updated imageFigureNumber.js to match root doc paths (e.g. /docs, /zh/docs) and preserve wrappers when images are linked. Also synced the issue and PR descriptions to keep the checks aligned.

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.

[Bug/Architecture] Build-time plugin state pollution in changelog generator and client-side figure caption race condition

1 participant