123123213weqw opened a new pull request, #5728:
URL: https://github.com/apache/rocketmq-dashboard/pull/5728

   ## Problem / Evidence
   
   `MetricsExplorer` touches `localStorage` directly in six places 
(`components/MetricsExplorer.tsx`):
   
   - the profiles effect reads the stored profile id 
(`localStorage.getItem(PROFILE_STORAGE_KEY)`) **inside the `.then`** of the 
successful profile-list request;
   - profile switching, auth-cancel restore and history restore call 
`setItem`/`removeItem` inline.
   
   The repo has `utils/browserStorage` — try/catch wrappers that exist 
precisely because raw storage access throws when the browser blocks it (Safari 
private mode, hardened cookie policies: `DOMException: Access is denied for 
this document`). Every other storage consumer goes through it; the explorer 
does not.
   
   Consequence of the raw read: on a browser with storage blocked, the 
successful `listMetricProfiles()` response is thrown away — the exception 
inside `.then` lands in `.catch`, and the explorer renders its "failed to load 
metric profiles" error banner forever even though the API works. A blocked 
`setItem` in `handleProfileChange` aborts the switch before `setProfileId` 
runs, so the profile select cannot change at all.
   
   ## Root cause / Fix
   
   Replace all six direct calls with `readLocalStorage` / `writeLocalStorage` / 
`removeLocalStorage`. A blocked store then degrades to "no remembered profile" 
instead of a dead explorer, which is exactly the contract the wrappers give 
every other page.
   
   ## Tests
   
   - New case `still loads the profiles when storage access is blocked` in 
`MetricsExplorer.test.tsx`: spies `Storage.prototype` get/set/remove to throw 
`DOMException('Access is denied for this document')`, then asserts the profile 
renders and the panel chart draws. Fails on the pre-fix code (the profile text 
never appears — verified the failure is the error-banner path).
   - Full `npx vitest run src/components/__tests__/MetricsExplorer.test.tsx` → 
36/36 passed; `npx tsc --noEmit -p tsconfig.app.json` clean; eslint on touched 
files clean.
   
   ## Risk
   
   Low: same wrapper behavior everywhere else in the app; the only change is 
that storage failures stop propagating into control flow.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to