Repository navigation
fix(theme-classic): show new announcement bar id on first load - #12752
aashish254 wants to merge 1 commit into
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Closing this as a duplicate of #12647, which has been open since Oct 14 and fixes the same root cause in the same file ( Their version is also broader than mine: it additionally maps the legacy misspelled default id Leaving #12753 (the CommonMark trailing-hash title fix) open, as that is a separate bug. (AI-assisted: drafted with an AI pair, reviewed by me.) |
fix(theme-classic): show new announcement bar id on first load
Pre-flight checklist
Motivation
Closes #12646.
When a user dismisses an announcement bar and the site later ships a new
announcement with a different
themeConfig.announcementBar.id, the new bar isnot visible on the first page load — it only appears after a second reload.
The
idis documented precisely as the way to re-show the bar to users whoclosed the previous one, so this defeats that feature.
Root cause: two places decide visibility and only one respects the
id.getAnnouncementBarInlineScript) setsdata-announcement-bar-initially-dismissedfromdocusaurus.announcement.dismissalone — it never readsdocusaurus.announcement.id. After a previous dismissal it setstrue.html[data-announcement-bar-initially-dismissed='true'] .announcementBar { display: none; }hides the bar.
AnnouncementBarProvidercorrectly detects the newid,resets
dismiss=falseand re-activates the bar — but nothing clears thestale data attribute, so the rendered bar stays hidden by CSS.
Fix: the inline script now compares the stored
docusaurus.announcement.idtothe configured id. A dismissal only hides the bar for the same announcement;
when the id differs, the bar is treated as not dismissed and shows immediately.
What changed
packages/docusaurus-theme-classic/src/inlineScripts.ts—
getAnnouncementBarInlineScriptnow takesannouncementIdand gates thedismissed state on the stored id matching the configured one.
packages/docusaurus-theme-classic/src/index.ts— passes
announcementBar.idinto the inline script.packages/docusaurus-theme-classic/src/__tests__/inlineScripts.test.ts— behavioral tests that actually execute the generated script against a mocked
localStorageand assert the resulting data attribute.Test Plan
Ran locally in the monorepo (
pnpm installcompleted, all packages built):pnpm test packages/docusaurus-theme-classic/src/__tests__/inlineScripts.test.ts→
Test Files 1 passed (1) / Tests 6 passed (6).inlineScripts.tstomainviagit stashand re-ran the suite →× re-shows the bar for a new id after a previous one was dismissedFAILED,other 5 passed. Restoring the fix makes all 6 pass. This proves the regression
test genuinely catches the bug rather than snapshotting the fix.
pnpm --filter @docusaurus/theme-classic build(runstsc --build) → clean,so
announcementBar.idtypechecks as theannouncementId: stringparam.pnpm exec eslint <3 changed files>→ 0 errors / 0 warnings.pnpm exec oxfmt --list-different <3 changed files>→ no diffs.pnpm exec cspell <3 changed files>→ 0 issues.Test cases added:
Test links
No dogfooding page added: this is a pre-hydration
<head>inline script +localStoragebehavior that isn't observable as a static deploy-preview page(it requires two sequential builds with different
announcementBar.idand abrowser dismissal in between). The unit tests exercise the exact generated
script and are the verifiable surface here. Happy to add a manual repro note if
maintainers want it in the test plan.
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs
Closes #12646.
How to submit (for the human contributor)
The repo's AGENTS.md prohibits an AI agent from opening the PR, so run these yourself:
Summary by CodeRabbit