siyuan-note/siyuan · error

Invalid view state field

Error message

Invalid view state field

What it means

validateField guard in the view-state service: a field name for stored view-state data is empty or longer than 2048 characters. Field keys index the persisted patch values, so oversized or blank keys are rejected.

Source

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

        checkResponse(response, "get");
        return isViewStateData(response.data) ? response.data : {};
    },
    async patch(key, values, removeKeys) {
        const {fetchSyncPost} = await import("./fetch");
        const response = await fetchSyncPost("/api/storage/patchViewState", {key, values, removeKeys});
        checkResponse(response, "patch");
    },
};

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 = {};

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Use concise, non-empty field keys
  2. Hash or truncate long generated field names below the 2048 limit
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at app/src/util/viewState.ts:70 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/56caabb87369c549. Report an issue: GitHub.