Skip to content

fix(core): convert between list types with different item schemas#8033

Open
bdbch wants to merge 3 commits into
mainfrom
fix/convert-crosslists
Open

fix(core): convert between list types with different item schemas#8033
bdbch wants to merge 3 commits into
mainfrom
fix/convert-crosslists

Conversation

@bdbch

@bdbch bdbch commented Jul 12, 2026

Copy link
Copy Markdown
Member

Fixes

Closes #2492

Changes and Review

  • toggleList now converts items when the list type changes (e.g. bulletList -> taskList).
  • Nested lists are recursively converted when the target item schema supports nesting, and flattened into sibling items when it does not.
  • Previously the command silently produced broken documents or did nothing.

Checklist

  • I have added a changeset if necessary.
  • I have added tests if possible.
  • I have made sure to test my changes myself.

Responsibility

  • I have reviewed and understand these changes, and I take responsibility for this PR, even if an AI agent created it.

Convert list items between different list types by recursively
converting nested lists when the target item schema supports it, and
flattening nested items into sibling items when it does not.
Copilot AI review requested due to automatic review settings July 12, 2026 20:33
@bdbch bdbch requested a review from a team as a code owner July 12, 2026 20:33
@netlify

netlify Bot commented Jul 12, 2026

Copy link
Copy Markdown

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 904a969
🔍 Latest deploy log https://app.netlify.com/projects/tiptap-embed/deploys/6a563e106c602b00084a0eec
😎 Deploy Preview https://deploy-preview-8033--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 904a969

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 72 packages
Name Type
@tiptap/core Patch
@tiptap/extension-audio Patch
@tiptap/extension-blockquote Patch
@tiptap/extension-bold Patch
@tiptap/extension-bubble-menu Patch
@tiptap/extension-code-block-lowlight Patch
@tiptap/extension-code-block Patch
@tiptap/extension-code Patch
@tiptap/extension-collaboration-caret Patch
@tiptap/extension-collaboration Patch
@tiptap/extension-details Patch
@tiptap/extension-document Patch
@tiptap/extension-drag-handle Patch
@tiptap/extension-emoji Patch
@tiptap/extension-file-handler Patch
@tiptap/extension-floating-menu Patch
@tiptap/extension-hard-break Patch
@tiptap/extension-heading Patch
@tiptap/extension-highlight Patch
@tiptap/extension-horizontal-rule Patch
@tiptap/extension-image Patch
@tiptap/extension-invisible-characters Patch
@tiptap/extension-italic Patch
@tiptap/extension-link Patch
@tiptap/extension-list Patch
@tiptap/extension-mathematics Patch
@tiptap/extension-mention Patch
@tiptap/extension-node-range Patch
@tiptap/extension-paragraph Patch
@tiptap/extension-strike Patch
@tiptap/extension-subscript Patch
@tiptap/extension-superscript Patch
@tiptap/extension-table-of-contents Patch
@tiptap/extension-table Patch
@tiptap/extension-text-align Patch
@tiptap/extension-text-style Patch
@tiptap/extension-text Patch
@tiptap/extension-twitch Patch
@tiptap/extension-typography Patch
@tiptap/extension-underline Patch
@tiptap/extension-unique-id Patch
@tiptap/extension-youtube Patch
@tiptap/extensions Patch
@tiptap/html Patch
@tiptap/markdown Patch
@tiptap/react Patch
@tiptap/static-renderer Patch
@tiptap/suggestion Patch
@tiptap/vue-2 Patch
@tiptap/vue-3 Patch
@tiptap/extension-drag-handle-react Patch
@tiptap/extension-drag-handle-vue-2 Patch
@tiptap/extension-drag-handle-vue-3 Patch
@tiptap/extension-bullet-list Patch
@tiptap/extension-ordered-list Patch
@tiptap/extension-list-item Patch
@tiptap/extension-list-keymap Patch
@tiptap/extension-task-item Patch
@tiptap/extension-task-list Patch
@tiptap/extension-table-cell Patch
@tiptap/extension-table-header Patch
@tiptap/extension-table-row Patch
@tiptap/extension-color Patch
@tiptap/extension-font-family Patch
@tiptap/extension-character-count Patch
@tiptap/extension-dropcursor Patch
@tiptap/extension-focus Patch
@tiptap/extension-gapcursor Patch
@tiptap/extension-history Patch
@tiptap/extension-placeholder Patch
@tiptap/pm Patch
@tiptap/starter-kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes toggleList in @tiptap/core so toggling between list types with different item node schemas (e.g. bulletList/listItemtaskList/taskItem) performs a structured conversion instead of producing broken documents or no-ops. It also updates the default demos to expose task lists in the UI and adds test coverage for the new conversion behavior.

Changes:

  • Add cross-item-type list conversion to toggleList, including recursive nested-list conversion and flattening when the target item schema can’t contain nested lists.
  • Introduce small conversion utilities (convertListItems, convertListItem, etc.) to keep toggleList logic focused and schema-valid.
  • Add/extend unit + demo e2e coverage and expose task list toggling in the default React/Vue/Svelte demos.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/extension-list/tests/taskItem.spec.ts Adds unit tests covering cross-type list conversion, nested conversion/flattening, and selection preservation.
packages/core/src/commands/utils/listConversionTypes.ts Adds shared types for list conversion context/state.
packages/core/src/commands/utils/flushPendingContent.ts Adds helper to flush accumulated item content into a schema-valid item node.
packages/core/src/commands/utils/findNodePosition.ts Adds helper to relocate selection by finding node positions after replacement.
packages/core/src/commands/utils/createNode.ts Adds safe node creation helper guarded by validContent and try/catch.
packages/core/src/commands/utils/convertListItems.ts Adds recursive conversion of all items in a list.
packages/core/src/commands/utils/convertListItem.ts Adds per-item conversion that may yield multiple output items (flattening).
packages/core/src/commands/utils/appendNestedList.ts Implements “preserve nested list if allowed; otherwise flatten” behavior.
packages/core/src/commands/utils/appendContentNode.ts Appends or splits item content based on schema validity.
packages/core/src/commands/toggleList.ts Integrates cross-item-type conversion into toggleList, including selection preservation.
demos/src/Examples/Default/Vue/index.vue Adds Task list button and enables TaskItem/TaskList extensions.
demos/src/Examples/Default/Svelte/index.svelte Adds Task list button and enables TaskItem/TaskList extensions.
demos/src/Examples/Default/React/menuBarState.ts Tracks isTaskList active state for menu rendering.
demos/src/Examples/Default/React/MenuBar.tsx Adds Task list toggle button.
demos/src/Examples/Default/React/index.tsx Enables TaskItem/TaskList extensions in the default React demo.
demos/src/Examples/Default/index.spec.ts Extends e2e assertions to include the Task list button + resulting DOM.
.changeset/fix-cross-type-list-toggle.md Adds a patch changeset documenting the user-facing fix in @tiptap/core.

Comment thread packages/extension-list/__tests__/taskItem.spec.ts
@bdbch

bdbch commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 56b57782-7a3b-49a9-88b3-9eee9f176a0f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

List toggling now converts between list types with different item schemas, recursively preserving nested lists when supported and flattening them otherwise. React, Svelte, and Vue demos now expose task-list controls with conversion and selection coverage.

Changes

Cross-type list toggling

Layer / File(s) Summary
List item conversion helpers
packages/core/src/commands/utils/*
Added recursive list-item conversion, nested-list handling, pending-content flushing, safe node creation, position lookup, and shared conversion types.
Cross-item-type toggle handling
packages/core/src/commands/toggleList.ts
toggleList now replaces incompatible list structures, remaps inline selections, and joins adjacent compatible lists.
Task-list demos and validation
demos/src/Examples/Default/..., packages/extension-list/__tests__/taskItem.spec.ts, packages/core/__tests__/appendNestedList.spec.ts, .changeset/*
Enabled task-list controls in the demos and added tests for conversions, nesting, flattening, attribute preservation, text preservation, and selection preservation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Editor
  participant toggleList
  participant ListConversion
  participant ProseMirror
  Editor->>toggleList: toggleTaskList()
  toggleList->>ListConversion: convert incompatible list items
  ListConversion->>ProseMirror: validate and create converted nodes
  toggleList->>ProseMirror: replace list and remap selection
  ProseMirror-->>Editor: updated task-list document
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: converting between list types with different item schemas.
Description check ✅ Passed The PR description follows the template and includes fixes, changes, checklist, and responsibility sections.
Linked Issues check ✅ Passed The changes and tests address #2492 by fixing task list toggling for nested list structures.
Out of Scope Changes check ✅ Passed The added demos, tests, utilities, and changeset all support the list conversion fix and stay in scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/commands/utils/appendNestedList.ts`:
- Around line 19-34: Update the nested list construction in appendNestedList to
preserve the source ordered-list attributes when calling createNode, including
start and type, instead of always passing null attrs. Keep the existing
validation and pendingContent flow unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 75a8e195-3c8b-4ab0-90b2-96c2f805012e

📥 Commits

Reviewing files that changed from the base of the PR and between a6f09e0 and 6ecc6fa.

📒 Files selected for processing (17)
  • .changeset/fix-cross-type-list-toggle.md
  • demos/src/Examples/Default/React/MenuBar.tsx
  • demos/src/Examples/Default/React/index.tsx
  • demos/src/Examples/Default/React/menuBarState.ts
  • demos/src/Examples/Default/Svelte/index.svelte
  • demos/src/Examples/Default/Vue/index.vue
  • demos/src/Examples/Default/index.spec.ts
  • packages/core/src/commands/toggleList.ts
  • packages/core/src/commands/utils/appendContentNode.ts
  • packages/core/src/commands/utils/appendNestedList.ts
  • packages/core/src/commands/utils/convertListItem.ts
  • packages/core/src/commands/utils/convertListItems.ts
  • packages/core/src/commands/utils/createNode.ts
  • packages/core/src/commands/utils/findNodePosition.ts
  • packages/core/src/commands/utils/flushPendingContent.ts
  • packages/core/src/commands/utils/listConversionTypes.ts
  • packages/extension-list/__tests__/taskItem.spec.ts

Comment thread packages/core/src/commands/utils/appendNestedList.ts
Update createNode to accept optional attrs and pass them
to the node type when creating. This ensures the nested
list retains the source list's attributes (e.g., start, type).
@bdbch

bdbch commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review again

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

@bdbch Got it! Kicking off another review now. 🐰

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bdbch

bdbch commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review again - I want to test something

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

@bdbch Sure thing! Kicking off another review for you. 🐰

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

Task item toggling causes various problems on list item structure

2 participants