fix(js): tolerate malformed bootstrap state
Report malformed data-slhx-st with slhx:state-error and continue binding the root with an empty atom store instead of letting state decode failures stop handlers, navigation, or push. req: state/004 req: state/006 req: runtime/001
This commit is contained in:
@@ -668,8 +668,13 @@
|
||||
function bootstrapState(root) {
|
||||
const encoded = root.getAttribute(STATE);
|
||||
if (!encoded) return;
|
||||
const store = atomStore(root);
|
||||
for (const atom of decodeAtomState(encoded)) store.set(String(atom.id), atom.bytes);
|
||||
try {
|
||||
const store = atomStore(root);
|
||||
for (const atom of decodeAtomState(encoded)) store.set(String(atom.id), atom.bytes);
|
||||
} catch (error) {
|
||||
atomStores.delete(root);
|
||||
emit(root, "slhx:state-error", String(error));
|
||||
}
|
||||
}
|
||||
|
||||
function decodeAtomState(encoded) {
|
||||
|
||||
Reference in New Issue
Block a user