Handle common app zoom shortcuts#768
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
| const readStoredZoomLevel = () => { | ||
| const storedValue = window.localStorage.getItem(APP_ZOOM_STORAGE_KEY); | ||
| const parsedValue = Number.parseFloat(storedValue ?? ""); | ||
|
|
||
| if (!Number.isFinite(parsedValue)) { | ||
| return DEFAULT_ZOOM_LEVEL; | ||
| } | ||
|
|
||
| return clampZoomLevel(parsedValue); | ||
| }; |
There was a problem hiding this comment.
🟡 Medium src/main.tsx:25
readStoredZoomLevel directly accesses window.localStorage.getItem() without exception handling. When the user has disabled cookies or the page runs in a strict iframe sandbox, this throws a SecurityError that propagates uncaught to the top level, halting main.tsx before ReactDOM.createRoot and leaving users with a blank white screen. Consider wrapping the localStorage access in a try-catch that returns DEFAULT_ZOOM_LEVEL on any exception.
+const readStoredZoomLevel = () => {
+ try {
+ const storedValue = window.localStorage.getItem(APP_ZOOM_STORAGE_KEY);
+ const parsedValue = Number.parseFloat(storedValue ?? "");
+
+ if (!Number.isFinite(parsedValue)) {
+ return DEFAULT_ZOOM_LEVEL;
+ }
+
+ return clampZoomLevel(parsedValue);
+ } catch {
+ return DEFAULT_ZOOM_LEVEL;
+ }
+};🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/web/src/main.tsx around lines 25-34:
`readStoredZoomLevel` directly accesses `window.localStorage.getItem()` without exception handling. When the user has disabled cookies or the page runs in a strict iframe sandbox, this throws a `SecurityError` that propagates uncaught to the top level, halting `main.tsx` before `ReactDOM.createRoot` and leaving users with a blank white screen. Consider wrapping the `localStorage` access in a try-catch that returns `DEFAULT_ZOOM_LEVEL` on any exception.
Evidence trail:
apps/web/src/main.tsx lines 25-33: `readStoredZoomLevel` function with direct `window.localStorage.getItem()` call and no try-catch. Line 59: `applyZoomLevel(readStoredZoomLevel())` inside `installAppZoomControls`. Lines 87-90: `installAppZoomControls()` called at line 88, `ReactDOM.createRoot()` at line 90. The exception path is: localStorage.getItem (line 26) → readStoredZoomLevel → installAppZoomControls (line 88) → uncaught → script halts before line 90.
Summary
Ctrl/Cmd++,-, and0Closes #281.
Before
After
Testing
bun run --filter=@t3tools/web typecheckbun run --filter=@t3tools/web testNote
Handle Ctrl/Cmd zoom keyboard shortcuts in the web app
keydownlistener in main.tsx that intercepts Ctrl/Cmd+,-, and0shortcuts (including numpad variants) and prevents the browser's default zoom behavior.document.documentElement.style.zoom, persisted tolocalStorageand restored on startup.0/Numpad0resets to the default level.📊 Macroscope summarized f270877. 1 file reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues