{"record":{"id":"3c1c9eac69eae5f9","repo":"siyuan-note/siyuan","slug":"invalid-view-state-patch","errorCode":null,"errorMessage":"Invalid view state patch","messagePattern":"Invalid view state patch","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/util/viewState.ts","lineNumber":30,"sourceCode":"\nexport interface IViewStateTransport {\n    get(key: string): Promise<TViewStateData>,\n    patch(key: string, values: TViewStateData, removeKeys: string[]): Promise<void>,\n}\n\nexport interface IViewStateServiceOptions {\n    flushDelay?: number,\n    transport?: IViewStateTransport,\n}\n\nconst DEFAULT_FLUSH_DELAY = 400;\nconst MAX_PATCH_ENTRIES = 1000;\nconst MAX_PATCH_BYTES = 256 * 1024;\n\nconst getPatchByteLength = (values: TViewStateData, removeKeys: string[]) => {\n    const json = JSON.stringify({values, removeKeys});\n    if (typeof json !== \"string\") {\n        throw new Error(\"Invalid view state patch\");\n    }\n    const goCompatibleJSON = json.replace(/[<>&\\u2028\\u2029]/g, character => {\n        return `\\\\u${character.charCodeAt(0).toString(16).padStart(4, \"0\")}`;\n    });\n    return new TextEncoder().encode(goCompatibleJSON).byteLength;\n};\n\nconst isViewStateData = (value: unknown): value is TViewStateData => {\n    return typeof value === \"object\" && value !== null && !Array.isArray(value);\n};\n\nconst checkResponse = (response: IWebSocketData, action: string) => {\n    if (!response || response.code !== 0) {\n        throw new Error(response?.msg || `Failed to ${action} view state`);\n    }\n};\n\nconst defaultTransport: IViewStateTransport = {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/app/src/util/viewState.ts#L12-L48","documentation":"getPatchByteLength guard in the view-state service: JSON.stringify of the {values, removeKeys} batch did not return a string, meaning the pending patch contains values that cannot be serialized (circular structures, undefined, symbols, or BigInt). The patch size cannot even be computed.","triggerScenarios":"Thrown at app/src/util/viewState.ts:30 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Store only JSON-serializable values (plain objects, strings, numbers, booleans, arrays, null)","Strip functions, undefined, symbols, and BigInt before calling set/patch","Circular-reference-safe clone the state before persisting"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}