Skip to content

feat(ui): add ui.createScope() lifecycle helper (SD-2918)#3091

Merged
caio-pizzol merged 3 commits into
mainfrom
caio/sd-2918-create-scope
May 2, 2026
Merged

feat(ui): add ui.createScope() lifecycle helper (SD-2918)#3091
caio-pizzol merged 3 commits into
mainfrom
caio/sd-2918-create-scope

Conversation

@caio-pizzol

Copy link
Copy Markdown
Contributor

Non-React consumers were rolling their own disposers to track subscription unsubscribes, custom-command registrations, and DOM listeners under one teardown call. ui.createScope() collects all three into a single primitive, and ui.destroy() cascades into every live scope so consumers do not need to remember a separate teardown path.

The minimum surface is small on purpose: add(teardown), register(...), on(target, type, listener), child(), and destroy(). Sugar like scope.subscribe(handle, fn) is held back until SD-2919 unifies subscribe and observe shapes across domain handles.

Post-destroy contract is documented inline so adapter authors do not have to discover it by experimentation. add runs the teardown synchronously, on is a no-op, register throws, child returns a destroyed scope.

  • Linear: SD-2918
  • 13 vitest cases cover the lifecycle: idempotent destroy, parent-before-child unwinding (LIFO), `ui.destroy()` cascade, custom-command auto-unregister, addEventListener/removeEventListener option parity, and that one failing teardown does not block the rest.

Verified: `pnpm --filter superdoc build` clean; `pnpm --filter @superdoc/super-editor test scope` passes 13/13.

createScope() collects subscription unsubscribes, custom-command
registrations, and DOM event listeners under one teardown call.
ui.destroy() cascades into every live scope before tearing down its
own resources, so non-React consumers no longer need to remember
multiple teardown calls.

The minimum surface is small on purpose: add(teardown), register(),
on(target, type, listener), child(), and destroy(). Convenience
sugar like scope.subscribe(handle, fn) is held back until SD-2919
unifies subscribe and observe shapes across domain handles.

Post-destroy contract: add() invokes the teardown synchronously; on()
is a no-op; register() throws; child() returns a destroyed scope. All
three are documented inline so framework adapter authors do not have
to discover them by experimentation.

Lifecycle is verified by 13 vitest cases covering: idempotent
destroy, parent-before-child unwinding (LIFO), ui.destroy() cascade,
custom-command auto-unregister, addEventListener / removeEventListener
option parity, and that one failing teardown does not block the rest.
@caio-pizzol
caio-pizzol requested a review from a team as a code owner May 2, 2026 14:46
@linear

linear Bot commented May 2, 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: 250bffaba7

ℹ️ 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 packages/super-editor/src/ui/create-super-doc-ui.ts
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Re-export SuperDocUIScope from the public superdoc/ui sub-entry so
  consumers can write `import type { SuperDocUIScope } from 'superdoc/ui'`
  without falling through to the inner workspace package.
- Guard ui.createScope() against post-destroy: returns an
  already-destroyed scope, mirroring the destroyed-parent behavior of
  scope.child(). Prevents a leak when consumers race shutdown / HMR
  teardown.
- Rewrite the misleading comment block in scope.ts that claimed
  untrack runs before consumer cleanups (it actually runs last,
  matching the parenthetical clarification in the same comment).
- Replace remaining em-dashes in types.ts and create-super-doc-ui.ts
  comments per project writing-style rule.
@caio-pizzol
caio-pizzol merged commit 635baf7 into main May 2, 2026
72 checks passed
@caio-pizzol
caio-pizzol deleted the caio/sd-2918-create-scope branch May 2, 2026 15:30
@superdoc-bot

superdoc-bot Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

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

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

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

@superdoc-bot

superdoc-bot Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

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

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

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

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

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

The release is available on GitHub release

@superdoc-bot

superdoc-bot Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

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

@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.

3 participants