Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement use node path plugin#4547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
delijah wants to merge3 commits intoudecode:main
base:main
Choose a base branch
Loading
fromDND-IT:implement-use-node-path-plugin

Conversation

@delijah
Copy link
Collaborator

Checklist

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

This implements a useNodePath hook, which will trigger a re-render, whenever a path of a node has been changed.

@codesandbox
Copy link

Review or Edit in CodeSandbox

Open the branch inWeb EditorVS CodeInsiders

OpenPreview

@changeset-bot
Copy link

changeset-botbot commentedAug 6, 2025
edited
Loading

🦋 Changeset detected

Latest commit:e4291ad

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

This PR includes changesets to release 43 packages
NameType
@platejs/coreMajor
platejsMajor
@platejs/utilsMajor
@platejs/autoformatMajor
@platejs/basic-nodesMajor
@platejs/basic-stylesMajor
@platejs/calloutMajor
@platejs/captionMajor
@platejs/code-blockMajor
@platejs/comboboxMajor
@platejs/commentMajor
@platejs/csvMajor
@platejs/cursorMajor
@platejs/dateMajor
@platejs/diffMajor
@platejs/dndMajor
@platejs/docxMajor
@platejs/emojiMajor
@platejs/excalidrawMajor
@platejs/find-replaceMajor
@platejs/floatingMajor
@platejs/indentMajor
@platejs/juiceMajor
@platejs/layoutMajor
@platejs/linkMajor
@platejs/list-classicMajor
@platejs/listMajor
@platejs/markdownMajor
@platejs/mathMajor
@platejs/mediaMajor
@platejs/mentionMajor
@platejs/playwrightMajor
@platejs/resizableMajor
@platejs/selectionMajor
@platejs/slash-commandMajor
@platejs/suggestionMajor
@platejs/tabbableMajor
@platejs/tableMajor
@platejs/tagMajor
@platejs/tocMajor
@platejs/toggleMajor
@platejs/yjsMajor
@platejs/aiMajor

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

vercelbot commentedAug 6, 2025
edited
Loading

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

NameStatusPreviewCommentsUpdated (UTC)
plate✅ Ready (Inspect)Visit Preview💬Add feedbackAug 6, 2025 1:52pm

@dosubotdosubotbot added the size:LThis PR changes 100-499 lines, ignoring generated files. labelAug 6, 2025
@dosubotdosubotbot added the core labelAug 6, 2025
@zbeyens
Copy link
Member

Can't we useuseEditorSelector instead of overridingapply?

@delijah
Copy link
CollaboratorAuthor

Can't we useuseEditorSelector instead of overridingapply?

If i understand correctly, we could only select props from the editor object, and trigger re-renders, whenever any node value or the editors selection changed, when usinguseEditorSelector.

My version is more fine grained, it will only react to node operations, not to text operations, nor to selection operations. Also it will react faster, immediately after and operation was applied, it doesn't wait for operations to be flushed to theonChange event. It also makes use of the PathRef feature, which belongs to the slate core and should be really performant.

But after this has been said, i am not too familiar yet with theuseEditorSelector capabilities yet. Maybe there would be a way of reaching similar performance? But as far as i saw, it can only react toonChange, 'onValueChange,onSelectionChangeand to changes of props of theeditor` object.

@delijah
Copy link
CollaboratorAuthor

delijah commentedAug 7, 2025
edited
Loading

What could be quite nice, would actually be something like that:

import{useEffect,useMemo,useState}from'react';import{Editor,typeNode}from'slate';import{ReactEditor,useSlateStatic}from'slate-react';exportconstuseNodePath=(node:Node)=>{consteditor=useSlateStatic();const[,setCacheKey]=useState(0);constpathRef=useMemo(()=>{constpath=ReactEditor.findPath(editor,node);if(path){returnEditor.pathRef(editor,path,{affinity:'backward',onChange:()=>{setCacheKey((prev)=>prev+1);},});}return{current:null,unref:()=>{},};// eslint-disable-next-line react-hooks/exhaustive-deps},[node]);useEffect(()=>()=>{pathRef.unref();},[pathRef],);returnpathRef.current;};

Of course the change handler on pathRefs would have to be implemented by slate-react.

Actually the hook could go into that package then. Or we could even think about a hook calledusePathRef.

What do you think about that@zbeyens ?

@delijah
Copy link
CollaboratorAuthor

Something like that:ianstormtaylor/slate#5930

@zbeyens
Copy link
Member

Yes that's better. I'm working on the onNodeChange prop right now.

@delijah
Copy link
CollaboratorAuthor

delijah commentedAug 7, 2025
edited
Loading

I get the feeling, that using the following might be sufficient 😅

constkey=editor.api.findKey(element);const{ path, selection}=useEditorSelector((editor)=>({path:editor.api.findPath(element),selection:editor.selection,}),[key],{equalityFn:(a,b)=>{constisPathEqual=a.path&&b.path ?PathApi.equals(a.path,b.path) :a.path===b.path;constisSelectionEqual=a.selection&&b.selection                    ?RangeApi.equals(a.selection,b.selection)                    :a.selection===b.selection;returnisPathEqual&&isSelectionEqual;},},);

@zbeyens
Copy link
Member

zbeyens commentedAug 7, 2025
edited
Loading

Perhaps we could add more parameters likeoperations (notoperation, sinceonChange can be called after many operations) touseEditorSelector so this could be optimized to a subset of operations. This needs to be patched first thoughianstormtaylor/slate#5863 (comment)

@delijah
Copy link
CollaboratorAuthor

Perhaps we could add more parameters likeoperations (notoperation, sinceonChange can be called after many operations) touseEditorSelector so this could be optimized to a subset of operations. This needs to be patched first thoughianstormtaylor/slate#5863 (comment)

Couldn't we just useeditor.operations for that?

@zbeyens
Copy link
Member

Yes if that's synced

@zbeyenszbeyens marked this pull request as draftSeptember 21, 2025 07:54
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

coresize:LThis PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@delijah@zbeyens

[8]ページ先頭

©2009-2025 Movatter.jp