fix: guard localStorage access in mobile warning dialog#1428
Merged
Conversation
iOS Safari in Private Browsing / Lockdown Mode throws SecurityError when localStorage is accessed. The mount effect read storage unguarded, surfacing an unhandled error on every page for those users. Wrap both reads and writes in try/catch and fail open.
🧹 PR Environment Cleaned UpThe PR environment has been successfully deleted. Deleted Resources:
All resources have been cleaned up and will no longer incur costs. |
ℹ️ No PR Environment to Clean UpNo PR environment was found for this PR. This is expected if:
|
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.
Summary
MobileWarningDialogreadslocalStoragein its mount effect without a guard.iOS Safari in Private Browsing / Lockdown Mode refuses storage access and throws
SecurityError: The operation is insecure.(DOMException code 18). Because thecomponent mounts globally via the root layout, an unguarded throw here surfaces
as a handled error on every page for those users.
Change
Wrap both the read (mount effect) and write (dismiss handler) in try/catch and
fail open: if storage is unavailable, show the warning and let dismiss work for
the session. No new abstraction; matches the inline try/catch pattern already
used in
app-banner.tsxandpending-template-runner.tsx.Note: landing as hardening, not asserting it closes the production iOS Safari
SecurityError, since the minified stack can't be mapped to an exact frame
without source maps. Leaving that issue open to verify against recurrence.