Skip to content

Commit 16dcb65

Browse files
committed
fix
1 parent 6f8c970 commit 16dcb65

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

docs/.vitepress/theme/components/state/deserialize.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ export function deserializeState(serializedString) {
1616
}
1717

1818
try {
19-
// For backward compatibility, it can address non-compressed data.
20-
const compressed = !serializedString.startsWith("eyJj");
21-
const decodedText = window.atob(serializedString);
22-
const jsonText = compressed
23-
? pako.inflate(decodedText, { to: "string" })
24-
: decodedText;
19+
const compressedString = window.atob(serializedString);
20+
const uint8Arr = pako.inflate(
21+
Uint8Array.from(compressedString, (c) => c.charCodeAt(0)),
22+
);
23+
24+
const jsonText = new TextDecoder().decode(uint8Arr);
2525
const json = JSON.parse(jsonText);
2626

2727
if (typeof json === "object" && json != null) {

docs/.vitepress/theme/components/state/serialize.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export function serializeState(state) {
2525
rules: state.rules ? getEnabledRules(state.rules) : undefined,
2626
};
2727
const jsonString = JSON.stringify(saveData);
28-
const compressedString = pako.deflate(jsonString, { to: "string" });
28+
29+
const uint8Arr = new TextEncoder().encode(jsonString);
30+
const compressedString = String.fromCharCode(...pako.deflate(uint8Arr));
2931
const base64 =
3032
(typeof window !== "undefined" && window.btoa(compressedString)) ||
3133
compressedString;

0 commit comments

Comments
 (0)