Repository navigation
fix(theme-classic): show announcement bar with new id on first page load (#12646) - #12749
hardikkaurani wants to merge 2 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
|
Hi @slorber, @lex111, @Josh-Cena, @yangshun! 👋 When an announcement bar's id is updated in hemeConfig.announcementBar.id, users who had dismissed the previous announcement had the bar hidden on their first page load because getAnnouncementBarInlineScript set data-announcement-bar-initially-dismissed='true' without checking if the stored id matches the newly configured id (#12646). This PR passes �nnouncementBar into the inline script and verifies docusaurus.announcement.id (with backward compatibility for the legacy misspelled �nnoucement-bar default id), ensuring new announcements display immediately on the first visit with comprehensive unit test coverage. Whenever you have a chance, I'd appreciate your review! Thank you! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
🔍 Why This PR is Merge-ReadyHi team, here is a detailed breakdown of why this PR is complete, minimal, and ready to merge: 1. Clear Problem & Root Cause Analysis
2. Surgical Fix with Full Compatibility
3. Edge Cases & Regressions Handled
4. Test Coverage & CI Status
Ready for maintainer sign-off! 🚀 |
Pre-flight checklist
Motivation
Fixes #12646.
When a user has dismissed an announcement bar and the site updates to a new announcement with a different
themeConfig.announcementBar.id, the new bar remains hidden on the first page load and only appears upon a second page reload.Root Cause:
getAnnouncementBarInlineScriptpreviously set<html data-announcement-bar-initially-dismissed>based solely ondocusaurus.announcement.dismiss === 'true', without comparingdocusaurus.announcement.idagainst the configured announcement barid.data-announcement-bar-initially-dismissed="true"applied to<html>, and the stylesheet (html[data-announcement-bar-initially-dismissed='true'] .announcementBar { display: none; }) kept the announcement hidden.AnnouncementBarProviderresetsdismissin storage on hydration when theiddiffers, but does not reset the HTML attribute, so the rendered bar remains visually hidden until the user refreshes a second time.Fix:
announcementBarintogetAnnouncementBarInlineScriptfrompackages/docusaurus-theme-classic/src/index.ts.getAnnouncementBarInlineScript, readdocusaurus.announcement.id, apply backward compatibility for the legacy misspelledannoucement-bardefault id (matchingAnnouncementBarProvider), and only treat the announcement bar as dismissed if the stored id matches the configured id.Test Plan
packages/docusaurus-theme-classic/src/__tests__/inlineScripts.test.tsverifying:falsetruefalse(solves Announcement bar with a newidstays hidden on first page load for users who dismissed the previous one #12646)annoucement-barmisspelled id compatibility ->trueTest links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs
idstays hidden on first page load for users who dismissed the previous one #12646