react-markdown-editor icon indicating copy to clipboard operation
react-markdown-editor copied to clipboard

ResizeObserver is not defined

Open aspnetde opened this issue 1 year ago • 3 comments

When adding the markdown editor to a current NextJs client component, building fails with a rather generic ReferenceError: ResizeObserver is not defined.

I don't have time for a reproduction test right now (sorry), but a quick workaround is using the polyfill as described here: https://stackoverflow.com/a/78560100/271150

aspnetde avatar Jul 31 '24 18:07 aspnetde

@aspnetde You might need to move it to client-side rendering instead of server-side. Add 'use client'; at the top of the code.

jaywcjlove avatar Sep 05 '24 19:09 jaywcjlove

@aspnetde You might need to move it to client-side rendering instead of server-side. Add 'use client'; at the top of the code.

I have this issue. Both the parent and the component have "use client"; at the top of code. First time to use Markdown.

<MarkdownEditor value={description} enablePreview enableScroll height="600px" className="w-full" onChange={(value, viewUpdate) => setDescription(value)} />

Screenshot 2024-09-10 164418

joelrb avatar Sep 10 '24 08:09 joelrb

Indeed, adding this to the component seems to have fixed the issue.

import ResizeObserver from 'resize-observer-polyfill'; global.ResizeObserver = ResizeObserver;

When adding the markdown editor to a current NextJs client component, building fails with a rather generic ReferenceError: ResizeObserver is not defined.

I don't have time for a reproduction test right now (sorry), but a quick workaround is using the polyfill as described here: https://stackoverflow.com/a/78560100/271150

joelrb avatar Sep 10 '24 08:09 joelrb