{"record":{"id":"df678b2d1c403de4","repo":"siyuan-note/siyuan","slug":"view-state-key-is-too-long","errorCode":null,"errorMessage":"View state key is too long","messagePattern":"View state key is too long","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/util/viewState.ts","lineNumber":80,"sourceCode":"const validateIdentityPart = (name: string, value: string) => {\n    if (!value) {\n        throw new Error(`View state ${name} must not be empty`);\n    }\n};\n\nconst validateField = (field: string) => {\n    if (!field || field.length > 2048) {\n        throw new Error(\"Invalid view state field\");\n    }\n};\n\nexport const getViewStateKey = (identity: IViewStateIdentity) => {\n    validateIdentityPart(\"scope\", identity.scope);\n    validateIdentityPart(\"surface\", identity.surface);\n    validateIdentityPart(\"hostID\", identity.hostID);\n    const key = [identity.scope, identity.surface, identity.hostID].map(encodeURIComponent).join(\":\");\n    if (key.length > 1024) {\n        throw new Error(\"View state key is too long\");\n    }\n    return key;\n};\n\nexport class ViewStateService {\n    public readonly key: string;\n    public readonly ready: Promise<void>;\n    private readonly data: TViewStateData = {};\n    private readonly pendingValues = new Map<string, TViewStateValue>();\n    private readonly pendingRemovals = new Set<string>();\n    private readonly flushDelay: number;\n    private readonly transport: IViewStateTransport;\n    private flushTimer?: ReturnType<typeof setTimeout>;\n    private flushChain: Promise<void> = Promise.resolve();\n    private destroyed = false;\n    private destroyPromise?: Promise<void>;\n\n    constructor(identity: IViewStateIdentity, options: IViewStateServiceOptions = {}) {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/app/src/util/viewState.ts#L62-L98","documentation":"Guard in getViewStateKey: the composite key built from scope/surface/hostID exceeds the maximum allowed key length for the kernel storage API. Any single identity part being extremely long pushes the joined key over the limit.","triggerScenarios":"Thrown at app/src/util/viewState.ts:80 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Shorten the identity parts (especially hostID-derived strings)","Hash long identifiers before composing the key"],"exampleFix":null,"handlingStrategy":"validation","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"}