Skip to content

fix(docs): initialize body for partial document data#7074

Open
hexf00 wants to merge 2 commits into
devfrom
fix/docs-create-document-empty-body
Open

fix(docs): initialize body for partial document data#7074
hexf00 wants to merge 2 commits into
devfrom
fix/docs-create-document-empty-body

Conversation

@hexf00

@hexf00 hexf00 commented Jun 12, 2026

Copy link
Copy Markdown
Member

Related downstream report: Univer CLI document creation followed by Facade text insertion failed because the created document had no body.

This PR makes partial document data without body initialize as a standard empty document in DocumentDataModel. This is necessary because Facade callers can create documents with only id and title, then naturally call appendText or insertText; before this change the document had no body and those APIs failed with The document body is empty.

The fix keeps a single document creation path by normalizing missing-body document snapshots at the core data-model boundary. It does not add CLI string matching or Facade fallback behavior. Documents that already provide a body keep their supplied body.

How to test them:

  • pnpm --filter @univerjs/core exec vitest run src/docs/data-model/__tests__/document-data-model.spec.ts src/docs/data-model/__tests__/empty-snapshot.spec.ts
  • pnpm --filter @univerjs/docs exec vitest run src/facade/__tests__/f-document-node.spec.ts
  • pnpm --filter @univerjs/core typecheck
  • pnpm --filter @univerjs/docs typecheck
  • git diff --check

Pull Request Checklist

  • Related downstream report is described in the PR description.
  • Naming convention is followed.
  • Unit tests have been added for the changes.
  • No breaking changes introduced in this PR.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

View Deployment

📑 Demo (React@19) Demo (React@16) 📚 Storybook
🔗 Preview link 🔗 Preview link 🔗 Preview link

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Playwright test results

passed  28 passed

Details

stats  28 tests across 12 suites
duration  7 minutes, 30 seconds
commit  a9d9f2b
info  For more information, see full report and artifacts

@jikkai jikkai requested a review from DR-Univer June 12, 2026 09:47
@jikkai

jikkai commented Jun 12, 2026

Copy link
Copy Markdown
Member

What is the original problem, and is there a way to reproduce it?

@hexf00

hexf00 commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

Original downstream issue: https://github.com/dream-num/univer-cli/issues/461

The problem was observed through Univer CLI SaC document authoring. Users could discover univerAPI.createDocument, but there was no safe path for constructing a legal document body. The natural Facade usage is:

const fDocument = univerAPI.createDocument({
  id: 'doc-demo',
  title: 'Demo Doc',
  documentStyle: {},
});

fDocument.appendText('Univer');
// The downstream report used insertParagraph after createDocument in the same missing-body path.

Before this PR, that partial document snapshot kept body missing, so the first text insertion failed with The document body is empty.

The downstream report also contains a second symptom: after users tried to work around the error by hand-writing a minimal body, the handcrafted body had invalid/incomplete document structure and two paragraph insertions collapsed into one paragraph. That is why the downstream issue looks like several separate gaps. The root blocker for this PR is the missing-body partial snapshot: callers should not need to handcraft dataStream / paragraphs / sectionBreaks just to create an editable empty document.

Expected behavior after this PR: DocumentDataModel normalizes document data without body to the standard empty document body (dataStream: '\r\n', one paragraph at 0, one section break at 1), and Facade text insertion works from there. Caller-supplied malformed bodies are not the target of this PR.

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.07%. Comparing base (7e8a1ae) to head (a9d9f2b).
⚠️ Report is 3 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #7074      +/-   ##
==========================================
- Coverage   62.16%   62.07%   -0.10%     
==========================================
  Files        2592     2595       +3     
  Lines      153097   153725     +628     
  Branches    34999    35178     +179     
==========================================
+ Hits        95177    95428     +251     
- Misses      57920    58297     +377     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants