fix(theme-common): report recoverable storage errors via reportError() (AI-assisted)#12021
Open
LeSingh1 wants to merge 1 commit into
Open
fix(theme-common): report recoverable storage errors via reportError() (AI-assisted)#12021LeSingh1 wants to merge 1 commit into
LeSingh1 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-flight checklist
Motivation
Closes #6747.
Today, when Docusaurus's
createStorageSlot(used for color mode, announcement bar dismissal, etc.) hits a failinglocalStorage/sessionStorageoperation — for example in an iframe, an incognito session, or under strict browser privacy settings — it logs toconsole.errorand continues. Site owners usingwindow.onerror,window.addEventListener('error', ...), or third-party error reporting may not see these failures today, even though they can be useful diagnostics for real browser/runtime conditions.The HTML spec's
reportError()API (Baseline since 2022) is purpose-built for this: it dispatches anErrorEventto global listeners just like an uncaught exception would, without actually throwing. This makes the error observable to host-page tooling while keeping the recovery path unchanged.What this PR does
reportRecoverableError(error)helper in@docusaurus/theme-commonthat prefersglobalThis.reportErrorand falls back toconsole.errorwhen it's unavailable (older browsers, some test runners).console.errorcall sites insidecreateStorageSlot(get/set/del/listen) to use the helper. Original messages are preserved as the newError's message; the underlying browser exception is preserved viaError.cause(a pattern already used elsewhere in the repo — seevitest.config.ts'ssnapshotErrorCause.tsserializer).console.errorcalls untouched: deprecation warnings incolorMode.tsx, locale diagnostics inusePluralForm.ts, and CLI/server logging. Those are not recoverable runtime errors.Scope was kept deliberately small so the helper and approach can be reviewed in isolation; follow-up PRs can migrate additional call sites incrementally if maintainers are happy with the pattern.
Test plan
yarn test packages/docusaurus-theme-common/src/utils/__tests__/errorUtils.test.ts— 2/2 pass, covers both thereportError-present and fallback paths.yarn test packages/docusaurus-theme-common— 108/108 pass, no regressions in existing storage / color mode behavior.yarn tsc --noEmitinpackages/docusaurus-theme-common— clean.yarn lint:js— no new errors or warnings on the changed files.Notes
This change is AI-assisted, per
AGENTS.md. The fallback toconsole.errorpreserves the existing behavior for older browsers and test environments withoutreportError.