Skip to content

refactor(superdoc): widen provider fields to CollaborationProvider (SD-2828)#3101

Merged
caio-pizzol merged 4 commits into
mainfrom
caio/SD-2828-provider-widening
May 4, 2026
Merged

refactor(superdoc): widen provider fields to CollaborationProvider (SD-2828)#3101
caio-pizzol merged 4 commits into
mainfrom
caio/SD-2828-provider-widening

Conversation

@caio-pizzol

Copy link
Copy Markdown
Contributor

SD-2828 closeout step 1/3+. Widens public provider fields from HocuspocusProvider to CollaborationProvider to match the runtime, which stores whatever provider the consumer passed via Config.modules.collaboration.provider (Hocuspocus, Liveblocks-Yjs, Tiptap-Collab, or any conforming adapter).

Public type change (consumer-observable):

 // packages/superdoc/src/core/types/index.ts
-  provider?: HocuspocusProvider;          // Document.provider
+  provider?: CollaborationProvider;
 // packages/superdoc/src/core/SuperDoc.js
-  /** @type {import('@hocuspocus/provider').HocuspocusProvider | undefined} */
+  /** @type {import('./types/index.js').CollaborationProvider | undefined} */
   provider;                                // SuperDoc.provider

Why: the previous typedef was Hocuspocus-specific. Non-Hocuspocus consumers (Liveblocks, Tiptap, custom adapters) saw superdoc.provider.X typed against Hocuspocus members that don't exist on their actual provider — a typedef that lied about the runtime. The runtime has always accepted any CollaborationProvider per the Config.modules.collaboration.provider typedef.

Migration: consumers calling Hocuspocus-specific members on these fields (e.g. superdoc.provider?.configuration, doc.provider?.subscribedToBroadcastChannel) need to narrow first. The typical if (provider) truthy pattern is unchanged.

Regression net: new fixture tests/consumer-typecheck/src/provider-collaboration-provider.ts pins the contract. Asserts SuperDoc.provider, Document.provider, and a hand-rolled minimal CollaborationProvider all typecheck. Two matrix scenarios added (bundler + node16), both mustPass.

Closes 2 of 3 originally-flagged provider errors in SuperDoc.js. The third (attachCollaboration call site, line ~815) is a separate concern — super-editor's attachCollaboration parameter expects an augmented CollaborationProvider & { awareness?; disconnect? } shape. That's an internal call-site issue, not a public-contract gap; tracked separately.

Verified:

  • pnpm --filter superdoc check:jsdoc → 3 gated files clean.
  • pnpm --filter superdoc build:es → no FAIL-level findings.
  • node tests/consumer-typecheck/typecheck-matrix.mjs → 37 passed (35 existing + 2 new), 0 failed.
  • pnpm exec vitest run src/core/SuperDoc.test.js → 78 passed.

Must stay the same: runtime behavior. The provider stored in superdoc.provider and doc.provider is the same value the consumer passed; only the public typedef widens to match.

Review: confirm emitted dist/superdoc/src/core/SuperDoc.d.ts shows provider: CollaborationProvider | undefined and dist/superdoc/src/core/types/index.d.ts shows Document.provider?: CollaborationProvider.

Next SD-2828 closeout PRs (per audit): SearchMatch publicization, ExportParams fieldsHighlightColor: string | null. ToolbarConfig triage to follow.

@caio-pizzol
caio-pizzol requested a review from a team as a code owner May 3, 2026 23:52
@linear

linear Bot commented May 3, 2026

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13ff0a9ab1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tests/consumer-typecheck/src/provider-collaboration-provider.ts Outdated
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…type

Reviewer flagged that widening Document.provider to CollaborationProvider
allows providers without disconnect/destroy methods (Liveblocks-style
adapters), so destroy() would throw under such providers.

Use double optional chain to guard both the provider and its method.
CollaborationProvider.disconnect and .destroy are optional, so cleanup
must guard the method, not just the provider. Adds a regression test
covering a minimal { on, off } provider — the shape Liveblocks-style
adapters use.
@caio-pizzol
caio-pizzol merged commit cc9aabe into main May 4, 2026
71 of 72 checks passed
@caio-pizzol
caio-pizzol deleted the caio/SD-2828-provider-widening branch May 4, 2026 00:40
@superdoc-bot

superdoc-bot Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in @superdoc-dev/mcp v0.3.0-next.37

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in vscode-ext v2.3.0-next.81

@superdoc-bot

superdoc-bot Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in @superdoc-dev/react v1.2.0-next.79

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc-cli v0.8.0-next.55

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc v1.30.0-next.38

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc-sdk v1.8.0-next.40

@superdoc-bot

superdoc-bot Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc-cli v0.9.0

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc v1.32.0

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in @superdoc-dev/mcp v0.4.0

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in @superdoc-dev/react v1.3.0

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in vscode-ext v2.4.0

@superdoc-bot

superdoc-bot Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in superdoc-sdk v1.9.0

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants