{"record":{"id":"917e5def8b2cdc5e","repo":"siyuan-note/siyuan","slug":"view-state-name-must-not-be-empty","errorCode":null,"errorMessage":"View state ${name} must not be empty","messagePattern":"View state (.+?) must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/util/viewState.ts","lineNumber":64,"sourceCode":"};\n\nconst defaultTransport: IViewStateTransport = {\n    async get(key) {\n        const {fetchSyncPost} = await import(\"./fetch\");\n        const response = await fetchSyncPost(\"/api/storage/getViewState\", {key});\n        checkResponse(response, \"get\");\n        return isViewStateData(response.data) ? response.data : {};\n    },\n    async patch(key, values, removeKeys) {\n        const {fetchSyncPost} = await import(\"./fetch\");\n        const response = await fetchSyncPost(\"/api/storage/patchViewState\", {key, values, removeKeys});\n        checkResponse(response, \"patch\");\n    },\n};\n\nconst 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;","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/app/src/util/viewState.ts#L46-L82","documentation":"validateIdentityPart guard in the view-state service: one of the key identity components (scope, surface, or hostID) is empty, so a valid composite view-state key cannot be built. The named part in the message is the empty one.","triggerScenarios":"Thrown at app/src/util/viewState.ts:64 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Supply non-empty scope, surface, and hostID when requesting a view-state key","Check callers that derive hostID from block or layout IDs for empty values"],"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"}