siyuan-note/siyuan · error

View state key is too long

Error message

View state key is too long

What it means

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.

Source

Thrown at app/src/util/viewState.ts:80

const validateIdentityPart = (name: string, value: string) => {
    if (!value) {
        throw new Error(`View state ${name} must not be empty`);
    }
};

const validateField = (field: string) => {
    if (!field || field.length > 2048) {
        throw new Error("Invalid view state field");
    }
};

export const getViewStateKey = (identity: IViewStateIdentity) => {
    validateIdentityPart("scope", identity.scope);
    validateIdentityPart("surface", identity.surface);
    validateIdentityPart("hostID", identity.hostID);
    const key = [identity.scope, identity.surface, identity.hostID].map(encodeURIComponent).join(":");
    if (key.length > 1024) {
        throw new Error("View state key is too long");
    }
    return key;
};

export class ViewStateService {
    public readonly key: string;
    public readonly ready: Promise<void>;
    private readonly data: TViewStateData = {};
    private readonly pendingValues = new Map<string, TViewStateValue>();
    private readonly pendingRemovals = new Set<string>();
    private readonly flushDelay: number;
    private readonly transport: IViewStateTransport;
    private flushTimer?: ReturnType<typeof setTimeout>;
    private flushChain: Promise<void> = Promise.resolve();
    private destroyed = false;
    private destroyPromise?: Promise<void>;

    constructor(identity: IViewStateIdentity, options: IViewStateServiceOptions = {}) {

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Shorten the identity parts (especially hostID-derived strings)
  2. Hash long identifiers before composing the key
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at app/src/util/viewState.ts:80 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/df678b2d1c403de4. Report an issue: GitHub.