fix: scope changelog plugin state per loadContent and derive figure locale from pathname (fixes #699) - #700
Conversation
… 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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: bhuvan-somisetty The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for project-hami ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
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! |
|
Warning Review limit reached
Next review available in: 55 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe 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. ChangesFigure caption locale handling
Changelog build state isolation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/client/imageFigureNumber.jssrc/plugins/changelog/index.js
…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>
|
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. |
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:
Changelog plugin state scoping (
src/plugins/changelog/index.js):publishTimes(Set) andauthorsMap(Object) were defined as module-level global singletons. During production multi-locale builds (npm run build), Docusaurus runsloadContent()sequentially forenthenzhin the same Node process. BecausepublishTimeswas never reset between locale runs, thezhpass detected all timestamps fromenas 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.publishTimesandauthorsMapinstantiation insideloadContent()and passed them down toprocessSection. Each build pass now starts with a clean slate, ensuring deterministic and matching timestamps across all locales.Client-side figure caption race condition & anchor preservation (
src/client/imageFigureNumber.js):onRouteDidUpdatescheduled triplesetTimeouttimers (100ms, 500ms, 1000ms) and readdocument.documentElement.langto decide betweenFigureand图caption prefixes. Because Docusaurus updates<html lang="...">asynchronously after route transitions complete, early timeout callbacks read stalelangvalues, outputting English captions on Chinese pages or vice versa. Additionally, root doc paths (/docsor/zh/docs) were missed by strict regex, and wrapping unlinked images detached<img>elements from parent<a>link tags.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 triplesetTimeoutcalls with a singlerequestAnimationFrametick, and ensured<figcaption>text is always updated dynamically.Which issue(s) this PR fixes:
Fixes #699
Checklist:
npm run lintandnpm run format:checkpassnpm run buildsucceeds for bothenandzhgit commit -s)