udecode / plate

Rich-text editor with shadcn/ui
https://platejs.org
Other
10.93k stars 671 forks source link

Server Endpoint for Converting HTML to Plate format #3177

Open zbeyens opened 5 months ago

zbeyens commented 5 months ago

Discussed in https://github.com/udecode/plate/discussions/3005

Originally posted by **mstelz** February 29, 2024 Using NextJS I have an `app/api/route.ts` with the following: ```typescript export async function POST(request: Request) { const editor = createPlateEditor({ plugins }); const json = deserializeHtml(editor, {element: request.body} return Response.json(json) } ``` but when I try to run it I receive the error > TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component What am I missing? I thought this was possible but correct me if I am wrong. Thanks in advance!

Funding

Fund with Polar

zbeyens commented 5 months ago

This PR made progress on this issue: https://github.com/udecode/plate/pull/3125. We now have a @udecode/plate-common/server entrypoint for createPlateEditor. In Plate 33, all serializers work server-side except the html one.

TODOs:

rbutera commented 4 months ago

so this is why deserializeHtml isn't working for me!

linhtrinh18 commented 2 months ago

@zbeyens I'm encountering the same issue with server-side HTML to Plate conversion in Next.js. Additionally, I'm unable to use serializeHtml even on the client-size Has anyone found a workaround or alternative approach for HTML to Plate conversion, either server-side or client-side in Next.js? Any insights or suggestions would be greatly appreciated.