siyuan-note/siyuan · error · Error

View state value is too large

Error message

View state value is too large

What it means

validateValue checks each field value at set/patch time by JSON-encoding {field: value} and comparing against MAX_PATCH_BYTES (256 KiB, the per-patch storage limit). Any single value that cannot fit into one patch alone is rejected immediately so the service never queues a patch that could never be split successfully.

Solutions

  1. Reduce the value size: store an ID or asset path instead of the full content
  2. Split large payloads across multiple fields (chunking) or persist them server-side and keep only the reference in view state
  3. Compress or trim the data before storing (e.g. store only the visible window of a list)
  4. Use a different persistence mechanism (e.g. a document attribute or server-side storage API) for oversized data

Example fix

// before
service.set("searchResult", JSON.stringify(entireResultList)); // > 256 KiB
// after: store a trimmed window or reference
service.set("searchResultIds", ids.slice(0, 500));
service.set("searchQuery", query);
Defensive patterns

Strategy: validation

Validate before calling

const MAX_PATCH_BYTES = 256 * 1024;
const valueBytes = (field, value) =>
  new TextEncoder().encode(JSON.stringify({[field]: value})).byteLength;
if (valueBytes("myField", myValue) > MAX_PATCH_BYTES) throw new Error("value too large for view state");

Type guard

const isStorableValue = (field: string, value: unknown): boolean =>
  new TextEncoder().encode(JSON.stringify({[field]: value})).byteLength <= 256 * 1024;

Try / catch

try {
  service.set("data", bigValue);
} catch (e) {
  if (e.message === "View state value is too large") {
    service.set("dataRef", await persistExternally(bigValue));
  }
}

Prevention

When it happens

Trigger: service.set(field, value) or service.patch({field: value}) where the UTF-8 byte length of the JSON-encoded value (plus field name, envelope, escaping of <>&/U+2028/U+2029) exceeds 262144 bytes.

Common situations: Persisting large documents, base64 images, big search results or serialized JSON blobs as a single view state field; accidental storage of a whole file's content instead of a reference/ID; accumulating an array in one field until it crosses the limit.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/b059c87ce997faaf. Report an issue: GitHub.

Appendix: source

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

                const nextRemoveKeys = [...removeKeys, field];
                if (count > 0 && (count >= MAX_PATCH_ENTRIES ||
                    getPatchByteLength(values, nextRemoveKeys) > MAX_PATCH_BYTES)) {
                    break;
                }
                removeKeys.push(field);
                this.pendingRemovals.delete(field);
                count++;
            }
        }
        if (count === 0) {
            throw new Error("View state patch cannot be split within the storage limits");
        }
        return {values, removeKeys};
    }

    private validateValue(field: string, value: TViewStateValue) {
        if (getPatchByteLength({[field]: value}, []) > MAX_PATCH_BYTES) {
            throw new Error("View state value is too large");
        }
    }

    private scheduleFlush() {
        this.clearFlushTimer();
        this.flushTimer = setTimeout(() => {
            this.flushTimer = undefined;
            this.flush().catch((error) => console.error(error));
        }, this.flushDelay);
    }

    private clearFlushTimer() {
        if (this.flushTimer !== undefined) {
            clearTimeout(this.flushTimer);
            this.flushTimer = undefined;
        }
    }

View on GitHub (pinned to 9f775e8a12)