Skip to content

Conversation

@felixfeng33
Copy link
Collaborator

Checklist

  • yarn typecheck
  • yarn lint:fix
  • yarn test
  • yarn brl
  • yarn changeset
  • ui changelog

@codesandbox
Copy link

codesandbox bot commented Jul 3, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot
Copy link

changeset-bot bot commented Jul 3, 2025

🦋 Changeset detected

Latest commit: 39ebdd9

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

This PR includes changesets to release 3 packages
Name Type
@platejs/core Patch
platejs Patch
@platejs/utils 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

@vercel
Copy link

vercel bot commented Jul 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 7:06am

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 3, 2025
@claude
Copy link
Contributor

claude bot commented Jul 3, 2025

Claude finished @felixfeng33's task —— View job


PR Review: getSelectedDomFragment

I've completed a thorough review of this PR. Here are my findings:

Todo List:

  • Read project guidelines (CLAUDE.md and Cursor rules)
  • Review code changes in all 4 files
  • Check for adherence to coding standards
  • Evaluate error handling
  • Assess unit test coverage
  • Verify changeset requirement
  • Check documentation needs
  • Provide comprehensive review feedback

Summary

This PR refactors the DOM selection logic by extracting fragment construction into a new utility function getSelectedDomFragment and deprecating the old getSelectedDomBlocks function.

Issues Found

🔴 Missing Changeset

The PR adds new functionality to the @platejs/core package but doesn't include a changeset. You need to add one by running:

yarn changeset

Select @platejs/core and mark this as a patch change since it's a refactor/improvement without breaking changes.

🔴 Missing Unit Tests

The new getSelectedDomFragment function has no unit tests. Given that getSelectedDomBlocks has comprehensive tests (307 lines covering various edge cases), the new function should have similar test coverage. Consider:

  • Creating packages/core/src/lib/static/utils/getSelectedDomFragment.spec.ts
  • Testing edge cases like empty selection, null selection, blocks without IDs, inline elements, etc.
  • Adapting the existing tests from getSelectedDomBlocks.spec.ts

🟡 Type Safety Issue

In getSelectedDomFragment.tsx line 22, you're using any type:

domBlocks.forEach((node: any) => {

Should be:

domBlocks.forEach((node: Element) => {

🟡 Potential Error Handling Issue

The function doesn't handle the case where editor.api.node() might return null. While you check for block existence, it would be safer to handle this explicitly.

🟡 Empty Array Return

Line 35 has return [] which should have a semicolon:

return [];

Positive Aspects

Good refactoring: Moving the fragment construction logic into a separate function improves code organization and reusability.

Backwards compatibility: Keeping getSelectedDomBlocks as deprecated maintains compatibility while guiding users to the new function.

Consistent API: The new function returns the processed fragment directly, which is more intuitive than returning DOM nodes.

Proper deprecation notice: The deprecation comment clearly indicates what to use instead.

Recommendations

  1. Add comprehensive unit tests for getSelectedDomFragment following the patterns in the existing test suite
  2. Add a changeset for this package update
  3. Fix the type safety issue by avoiding any type
  4. Consider adding JSDoc to document the function's purpose and return value:
/**
 * Get Slate nodes from the DOM selection as a fragment
 * @param editor - The Slate editor instance
 * @returns Array of Descendant nodes from the selection, or empty array if no valid selection
 */
  1. Consider error boundaries for the editor.api.node() call to handle potential edge cases

Next Steps

Please address the missing changeset and unit tests before merging. The type improvements and documentation would also enhance code quality.

@claude
Copy link
Contributor

claude bot commented Jul 3, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@felixfeng33
Copy link
Collaborator Author

/changeset

@claude
Copy link
Contributor

claude bot commented Jul 3, 2025

Claude finished @felixfeng33's task —— View job


Changeset Created ✅

Todo List:

  • Read changeset guide at .claude/commands/changeset.md
  • Analyze code changes to determine change type
  • Create changeset file for @platejs/core
  • Check if registry changes require changelog.mdx update
  • Finalize and commit changeset

Summary:
I've successfully created and committed a changeset for this PR:

  • File: .changeset/core-patch-getSelectedDomFragment.md
  • Change Type: patch (refactoring/improvement, backward-compatible)
  • Package: @platejs/core

The changeset documents:

  1. The new getSelectedDomFragment utility function that returns Slate nodes from DOM selection
  2. The deprecation of getSelectedDomBlocks in favor of the new function

No registry changes were detected, so no changelog.mdx update was needed.


Co-authored-by: Felix Feng <felixfeng33@users.noreply.github.com>
@felixfeng33 felixfeng33 changed the title getSelectedDomFragment Add getSelectedDomFragment Jul 3, 2025
@felixfeng33 felixfeng33 merged commit 7047a16 into main Jul 3, 2025
6 of 7 checks passed
@felixfeng33 felixfeng33 deleted the getSelectedDomFragment branch July 3, 2025 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dom size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants