Files
outline/shared/utils/ProsemirrorDataHelper.test.ts
T
Tom MoorandClaude Opus 4.8 863f09371c perf: Keep vendor-prosemirror out of the eager authenticated bundle (#13026)
* perf: Keep vendor-prosemirror out of the eager authenticated bundle

Split the data-only helpers `getEmpty` and `isEmpty` out of
`ProsemirrorHelper` into a new prosemirror-free `ProsemirrorDataHelper`
module, and point the sidebar, DocumentNew, and other lightweight
callers at it. This removes the static edge from the authenticated entry
graph to `prosemirror-model`, deferring the ~653 KB vendor-prosemirror
chunk until an editor surface is actually opened.

Fixes #13005

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Use non-optional collection.data in defined branch

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 07:12:28 -04:00

66 lines
2.0 KiB
TypeScript

import type { ProsemirrorData } from "../types";
import { ProsemirrorDataHelper } from "./ProsemirrorDataHelper";
describe("ProsemirrorDataHelper", () => {
describe("getEmpty", () => {
it("returns a new empty document each call", () => {
const a = ProsemirrorDataHelper.getEmpty();
const b = ProsemirrorDataHelper.getEmpty();
expect(a).toEqual({
type: "doc",
content: [{ content: [], type: "paragraph" }],
});
expect(a).not.toBe(b);
});
it("produces data considered empty", () => {
expect(
ProsemirrorDataHelper.isEmpty(ProsemirrorDataHelper.getEmpty())
).toBe(true);
});
});
describe("isEmpty", () => {
it("returns false when the root is not a doc", () => {
const data: ProsemirrorData = { type: "paragraph" };
expect(ProsemirrorDataHelper.isEmpty(data)).toBe(false);
});
it("returns true for a doc with no content", () => {
expect(ProsemirrorDataHelper.isEmpty({ type: "doc" })).toBe(true);
expect(ProsemirrorDataHelper.isEmpty({ type: "doc", content: [] })).toBe(
true
);
});
it("returns true for a doc with a single empty paragraph", () => {
const data: ProsemirrorData = {
type: "doc",
content: [{ type: "paragraph", content: [] }],
};
expect(ProsemirrorDataHelper.isEmpty(data)).toBe(true);
});
it("returns false when the single paragraph has content", () => {
const data: ProsemirrorData = {
type: "doc",
content: [
{ type: "paragraph", content: [{ type: "text", text: "hi" }] },
],
};
expect(ProsemirrorDataHelper.isEmpty(data)).toBe(false);
});
it("returns false when there are multiple nodes", () => {
const data: ProsemirrorData = {
type: "doc",
content: [
{ type: "paragraph", content: [] },
{ type: "paragraph", content: [] },
],
};
expect(ProsemirrorDataHelper.isEmpty(data)).toBe(false);
});
});
});