Wrap localStorage JSON.parse in try-catch in cytoscapeMap
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -328,13 +328,10 @@ export default function cytoscapeMap(
|
||||
cytoscapeStore.loadPositionsFromStorage(rank);
|
||||
// Check if localStorage has previously saved visit data.
|
||||
// If saved node positions exist, restore them for rendering.
|
||||
if (
|
||||
localStorage.getItem(SAVE_KEY_NAME) &&
|
||||
JSON.parse(localStorage.getItem(SAVE_KEY_NAME))
|
||||
) {
|
||||
const allGraphsRemembered = JSON.parse(
|
||||
localStorage.getItem(SAVE_KEY_NAME),
|
||||
);
|
||||
try {
|
||||
const raw = localStorage.getItem(SAVE_KEY_NAME);
|
||||
if (raw) {
|
||||
const allGraphsRemembered = JSON.parse(raw);
|
||||
const currentGraphNodesRemembered = allGraphsRemembered[
|
||||
cytoscapeStore.currentGraphId
|
||||
]
|
||||
@@ -349,6 +346,9 @@ export default function cytoscapeMap(
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Corrupted localStorage data; ignore and use defaults
|
||||
}
|
||||
// Save the current positions of all nodes when the view is first entered
|
||||
const allNodes = cy.nodes();
|
||||
allNodes.forEach((nodeFirstlySave) => {
|
||||
|
||||
Reference in New Issue
Block a user