Skip to content

fix(theme-classic): check announcementBar id in inline dismiss script - #13097

Open
saiv0n wants to merge 1 commit into
meta:mainfrom
saiv0n:fix/announcement-bar-new-id-visibility
Open

saiv0n wants to merge 1 commit into
meta:mainfrom
saiv0n:fix/announcement-bar-new-id-visibility

Conversation

@saiv0n

@saiv0n saiv0n commented Nov 21, 2026 •

Copy link
Copy Markdown

getAnnouncementBarInlineScript() previously only checked docusaurus.announcement.dismiss === 'true' and ignored docusaurus.announcement.id. When a site updated themeConfig.announcementBar.id, users who had dismissed the previous announcement still received data-announcement-bar-initially-dismissed="true" on first load, keeping the newly rendered bar hidden via CSS until a second page load.

This passes announcementBar into getAnnouncementBarInlineScript() and only marks the bar initially dismissed when both docusaurus.announcement.dismiss === 'true' and docusaurus.announcement.id matches the configured announcementBar.id (safely JSON-escaped for inline <script>).

Fixes #12646

Summary by CodeRabbit

  • Bug Fixes
    • Announcement bar dismissal is now tied to the current announcement. If the announcement changes, a previously saved dismissal won’t hide the new announcement; matching announcements remain dismissed across visits.

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Nov 21, 2026
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The announcement-bar inline script now checks whether the stored announcement ID matches the configured ID before marking the bar as initially dismissed. The caller passes the announcement-bar configuration, and tests cover matching and changed IDs, namespaced storage, and special characters.

Changes: Announcement bar visibility

Layer / File(s) Summary
Check the configured announcement ID
packages/docusaurus-theme-classic/src/inlineScripts.ts, packages/docusaurus-theme-classic/src/index.ts, packages/docusaurus-theme-classic/src/__tests__/inlineScripts.test.ts
The inline script marks the bar as dismissed only when the stored dismissal flag is true and the stored announcement ID matches the configured ID. The caller passes the announcement-bar configuration. Tests cover matching and changed IDs, namespaced storage, and special characters.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • meta/docusaurus#12838: Passes the configured announcement ID to the inline script and compares it with the stored ID.
  • meta/docusaurus#12842: Compares the stored ID with the configured ID before marking the bar as dismissed.
  • meta/docusaurus#12931: Passes the announcement configuration to the inline script and checks the stored ID.
Merge Risk: Minimal · up to b4416

This change makes a new announcement bar appear on first load after its configured id changes. The change is narrow and covered by tests, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the inline announcement-bar dismiss script now checks the stored announcement ID against the configured announcementBar id. The raw summary confirms that getAnnounceme…
Linked Issues check Passed [#12646] requires the inline script to stop hiding a new announcement bar for users who dismissed the previous one. At the reviewed head, `getAnnouncementBarInlineScript({announcementBar, siteStorage}…
Out of Scope Changes check Passed The whole-PR changes, as described by the supplied summary and confirmed in inlineScripts.ts at head, are limited to: (1) inlineScripts.ts, which adds the ID check to the dismissal logic; (2) `ind…
Full details: Title check

Explanation

The title names the main change: the inline announcement-bar dismiss script now checks the stored announcement ID against the configured announcementBar id. The raw summary confirms that getAnnouncementBarInlineScript now receives announcementBar and compares the stored ID with announcementBar.id, which matches the linked issue's goal of showing a new bar after its id changes. The title is specific and uses the conventional fix(scope) format.

Full details: Linked Issues check

Explanation

[#12646] requires the inline script to stop hiding a new announcement bar for users who dismissed the previous one. At the reviewed head, getAnnouncementBarInlineScript({announcementBar, siteStorage}) in packages/docusaurus-theme-classic/src/inlineScripts.ts builds isDismissed() as localStorage['docusaurus.announcement.dismiss'] === 'true' &amp;&amp; localStorage['docusaurus.announcement.id'] === &lt;JSON-encoded announcementBar.id&gt;. The attribute data-announcement-bar-initially-dismissed is set from this result. When the stored ID is the old ID, the function returns false, so the CSS rule does not hide the new bar on first load. The ID is JSON-encoded with &lt; replaced by \u003c, which keeps the inline script safe. The raw summary states that index.ts now passes announcementBar to this function. I read the head file directly, but I could not read the index.ts diff because the changed blobs were unavailable. That call-site change is therefore based on the supplied summary. The test file summary also reports tests for matching ID, differing ID, and special characters in the ID. I did not read those tests directly. The issue requirement is met by the inline script code at head.

Full details: Out of Scope Changes check

Explanation

The whole-PR changes, as described by the supplied summary and confirmed in inlineScripts.ts at head, are limited to: (1) inlineScripts.ts, which adds the ID check to the dismissal logic; (2) index.ts, which passes announcementBar to that function; and (3) inlineScripts.test.ts, which adds tests for this behavior. All of these directly implement or verify the [#12646] requirement. No unrelated change is reported. The index.ts diff and test file contents were not read directly because the diff was unavailable, so this verdict relies partly on the summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a4a59c4-3c16-4ddb-82f2-c7e8e5a5ce9f
Commits

Reviewing files that changed from the base of the PR and between 809ffff and b44163b.

Files selected for processing: 3

  • packages/docusaurus-theme-classic/src/__tests__/inlineScripts.test.ts
  • packages/docusaurus-theme-classic/src/index.ts
  • packages/docusaurus-theme-classic/src/inlineScripts.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@netlify

netlify Bot commented Nov 21, 2026

Copy link
Copy Markdown

✅ [V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit b44163b
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6b01e31ef107efac3fe4bcfa
😎 Deploy Preview https://deploy-preview-13097--docusaurus-2.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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Announcement bar with a new id stays hidden on first page load for users who dismissed the previous one

1 participant