Skip to content

Re-show dismissed announcement bar after 10 days - #1778

Open
derek-netwrix wants to merge 1 commit into
devfrom
announcement-bar-dismiss-expiry
Open

derek-netwrix wants to merge 1 commit into
devfrom
announcement-bar-dismiss-expiry

Conversation

@derek-netwrix

Copy link
Copy Markdown
Contributor

Summary

  • Docusaurus remembers a dismissed announcement bar indefinitely (until its id changes). This adds src/clientModules/announcementBarExpiry.js, which stamps the first time it sees the bar dismissed and clears the dismissal once the stamp is older than 10 days.
  • Runs at module load (before the bar renders on a fresh page load) and on every route update.
  • Registered in clientModules in docusaurus.config.js.

Notes

  • Per browser: clearing site data or using another browser/private mode brings the bar back sooner. Changing announcementBar.id still re-shows it to everyone immediately.
  • If storage is unavailable, it falls back to Docusaurus's default behavior.
  • Logic checked with a fake localStorage: first sighting stamps, 9 days stays dismissed, 11 days clears.
  • Follow-up to Add scoped EPP Navigator announcement bar to Endpoint Protector docs #1710.

Generated with AI

Co-Authored-By: Claude Code ai@netwrix.com

Docusaurus remembers a dismissal forever. Add a client module that
stamps the first time it sees the bar dismissed and clears the
dismissal once the stamp is older than 10 days.

Generated with AI

Co-Authored-By: Claude Code <ai@netwrix.com>
@github-actions

Copy link
Copy Markdown
Contributor

Code Review

The config change and the new client module are fine. The SSR guard is correct, storage errors are caught, the storage key matches Docusaurus's unnamespaced default (no future.experimental_storage is set), and nothing touches the KB pipeline, sidebars, or workflows. I found one minor behavior issue:

The bar can stay hidden on the page load where the dismissal expires (src/clientModules/announcementBarExpiry.js)

Docusaurus injects an inline <head> script that runs before any client module. It reads docusaurus.announcement.dismiss and sets data-announcement-bar-initially-dismissed="true" on <html>. The theme CSS (html[data-announcement-bar-initially-dismissed='true'] .announcementBar { display: none; }) uses that attribute to hide the bar without a layout shift.

On the load where the 10 days run out, the attribute is already true by the time this module removes the storage key. React then renders the bar, but the CSS still hides it, and the attribute isn't reset during client-side navigation. So the bar only comes back on the next full page load, not on the first visit after 10 days as the PR description says.

A small fix is to reset the attribute when the dismissal is cleared:

} else if (Date.now() - stamp > SHOW_AGAIN_AFTER_DAYS * 24 * 60 * 60 * 1000) {
  localStorage.removeItem(DISMISS_KEY);
  localStorage.removeItem(STAMP_KEY);
  document.documentElement.setAttribute('data-announcement-bar-initially-dismissed', 'false');
}

This is worth checking in a browser: set epp.announcement.dismissedAt to an old timestamp and hard-reload. It isn't a build or routing risk.

Two smaller notes, no change needed:

  • A dismissal is only stamped on the next route update or page load, so the 10 days count from the first navigation after the user dismisses the bar. In practice that's close enough.
  • STAMP_KEY uses the epp. prefix for the whole site. That's harmless, and if the bar's id changes later, an old stamp is cleared correctly, because the first branch removes it whenever the dismiss key is not 'true'.

@derek-netwrix
derek-netwrix requested a review from jth-nw October 26, 2026 15:41

This branch was previously deployed

1 inactive deployment
development — 9721bee3 Deployed Oct 26, 2026 by derek-netwrix via build-and-deploy #4834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant