zjncs opened a new pull request, #4575:
URL: https://github.com/apache/rocketmq-dashboard/pull/4575
### Which Issue(s) Are Addressed
No issue yet; found while auditing the prompt template library added in
#4215.
### Brief Description
`readCustomPromptTemplates` caught a failing `JSON.parse` in the same
`catch` as a failing `storage.getItem`, so a corrupt payload under
`rocketmq-studio-ai-prompt-templates` was conflated with blocked storage:
* the modal showed the "browser storage unavailable" alert even though
storage works fine;
* every subsequent `saveCustomPromptTemplate` returned `storage_unavailable`
and every `deleteCustomPromptTemplate` returned `false`, so the bad payload
could never be overwritten from the UI - the only recovery was deleting the
localStorage key by hand in devtools.
This was internally inconsistent with the wrong-shape path one line below: a
payload that parses but is not an array (e.g. a JSON object) is already treated
as "no templates, storage available" and is repaired by the next save.
The fix splits the reads so each failure maps to the state it actually
describes:
* `getItem` throwing still reports `storageAvailable: false` (genuinely
blocked storage, unchanged behaviour, still covered by the existing test);
* `JSON.parse` throwing now behaves like the wrong-shape case - no
templates, `storageAvailable: true` - so the next save overwrites the key and
repairs it.
### How Did You Test This?
Fail-before / pass-after with the new vitest case `repairs corrupt stored
JSON instead of treating storage as unavailable` (stores `{"broken":` under the
key, then asserts the catalog reports storage available and a save succeeds and
persists):
```
NODE_OPTIONS=--no-experimental-webstorage npx vitest run
src/pages/ai/promptTemplates.test.ts # before fix: 1 failed | 11 passed
NODE_OPTIONS=--no-experimental-webstorage npx vitest run
src/pages/ai/promptTemplates.test.ts # after fix: 12 passed
```
(`--no-experimental-webstorage` only stops Node 25's native `localStorage`
global from shadowing jsdom's in the local environment; CI does not need it.)
Full web suite, lint and typecheck after the fix:
```
NODE_OPTIONS=--no-experimental-webstorage npm test # Test Files 122
passed, Tests 1035 passed
npm run lint # 0 errors (10
pre-existing warnings elsewhere)
tsc -b # clean
```
### Checklist
- [x] Code follows the project's coding style (Conventional Commits, lint
passes)
- [x] Added/updated tests covering the fix
- [x] All tests pass locally
Signed-off-by: zjncs <[email protected]>
--
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]