Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalizeNode updates the same nodes' property #4641

Open
raitucarp opened this issue Oct 30, 2021 · 4 comments
Open

normalizeNode updates the same nodes' property #4641

raitucarp opened this issue Oct 30, 2021 · 4 comments
Labels

Comments

@raitucarp
Copy link

raitucarp commented Oct 30, 2021

I want to assign each element node to have an Id such that:

editor.normalizeNode = ([node, path]) => {
    if (Element.isElement(node)) {
       if (!node.id) {
            const seed = Node.string(node);
            const id = createId(seed);

            Transforms.setNodes(editor, { id }, { at: path });
       }
    }
    normalizeNode([node, path]);
}

Unfortunately, all nodes have the same Id after normalized, what is going on here? Why transforms.setNodes at specified path causes all nodes have same property?

@raitucarp raitucarp added the bug label Oct 30, 2021
@raitucarp raitucarp changed the title normalizeNode causes updating all nodes' property normalizeNode updates the same nodes' property Oct 30, 2021
@BrentFarese
Copy link
Collaborator

Not sure what’s going on here but it’s likely not a Slate issue. Post a sandbox if you want help or I would ask it in Slack really. Not sure there is any bug here with Slate.

@raitucarp
Copy link
Author

Hold on, I'll provide the sandbox later...

@fkhasib
Copy link

fkhasib commented Dec 29, 2021

@BrentFarese I am facing the same issue, it happens because whenever you press enter inside a paragraph(InsertBreak) is invoked and its split the nodes, it copies all the paragraph properties to the new paragraph, it doesn't even reach the normalize logic since it will have first paragraph id on it by the code above, same happens inside list item
If you follow insertBreak logic
and see

Transforms.splitNodes(editor, { always: true })

const properties = Node.extractProps(node)

Any solution how can we exclude the id property from the copy?

@iamkhalidbashir
Copy link

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants