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);
|
cytoscapeStore.loadPositionsFromStorage(rank);
|
||||||
// Check if localStorage has previously saved visit data.
|
// Check if localStorage has previously saved visit data.
|
||||||
// If saved node positions exist, restore them for rendering.
|
// If saved node positions exist, restore them for rendering.
|
||||||
if (
|
try {
|
||||||
localStorage.getItem(SAVE_KEY_NAME) &&
|
const raw = localStorage.getItem(SAVE_KEY_NAME);
|
||||||
JSON.parse(localStorage.getItem(SAVE_KEY_NAME))
|
if (raw) {
|
||||||
) {
|
const allGraphsRemembered = JSON.parse(raw);
|
||||||
const allGraphsRemembered = JSON.parse(
|
|
||||||
localStorage.getItem(SAVE_KEY_NAME),
|
|
||||||
);
|
|
||||||
const currentGraphNodesRemembered = allGraphsRemembered[
|
const currentGraphNodesRemembered = allGraphsRemembered[
|
||||||
cytoscapeStore.currentGraphId
|
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
|
// Save the current positions of all nodes when the view is first entered
|
||||||
const allNodes = cy.nodes();
|
const allNodes = cy.nodes();
|
||||||
allNodes.forEach((nodeFirstlySave) => {
|
allNodes.forEach((nodeFirstlySave) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user