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

HTMLReact Serializer does not work #3687

Closed
SLey3 opened this issue Oct 29, 2024 · 2 comments
Closed

HTMLReact Serializer does not work #3687

SLey3 opened this issue Oct 29, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@SLey3
Copy link

SLey3 commented Oct 29, 2024

Description

It seems that when the htmlReact serializer tries to serialize the plate JSON data to HTML, an invalid hook call error occurs. Using the error log, it could be traced back to the useIsVisible hook in the toggleIndexAtom file located within the @udecode/plate-toggle library. I followed the docs in terms of calling the serializer and I placed it in the following function:

    const serializeEditorContent = () => {
        return editor.api.htmlReact.serialize({
            nodes: editor.children,
            dndWrapper: (props) => <DndProvider backend={HTML5Backend} {...props} />
        });
    };

Reproduction URL

No response

Reproduction steps

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

Plate version

39.1.8

Slate React version

0.110.1

Screenshots

No response

Logs

react-dom.development.js:15408 Uncaught (in promise) Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
    at Object.throwInvalidHookError (react-dom.development.js:15408:9)
    at Object.useContext (react.development.js:1618:21)
    at useAtomStore (createAtomProvider.tsx:33:30)
    at useStore2 (createAtomStore.ts:244:26)
    at Object.store (createAtomStore.ts:328:7)
    at usePlateEditorStore (createPlateStore.ts:90:40)
    at usePlateSelectors (createPlateStore.ts:134:17)
    at useEditorRef (useEditorRef.ts:15:6)
    at useEditorPlugin (useEditorPlugin.ts:20:18)
    at useIsVisible (toggleIndexAtom.ts:53:25)

Browsers

Chrome

@SLey3 SLey3 added the bug Something isn't working label Oct 29, 2024
@slavik-chapelskyi
Copy link

I've run into the same issue. When I try to comment out the toggle plugins, I encounter similar problems with other plugins. It seems that the HTML serialization is completely broken. From my quick review of the code, it appears that the process tries to recreate elements outside of the React tree and then convert them into an HTML string, which breaks the rules of React.

@zbeyens
Copy link
Member

zbeyens commented Oct 30, 2024

Duplicate of #2804. See this workaround.

@zbeyens zbeyens closed this as completed Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants