focusreactive / sanity-plugin-inline-svg-input

Sanity plugin to upload and preview inline SVGs
https://www.npmjs.com/package/@focus-reactive/sanity-plugin-inline-svg-input
MIT License
19 stars 2 forks source link

TypeError: DOMPurify__default.default.sanitize is not a function #16

Open mojtaba-shahverdi opened 7 months ago

mojtaba-shahverdi commented 7 months ago

<InlineSvgPreviewComponent value={category.svgIcon} >

Error: TypeError: DOMPurify__default.default.sanitize is not a function

chenaski commented 6 months ago

Hi @mojtaba-shahverdi, could you please share more context:

And any other details you think might be helpful, thanks!

chenaski commented 2 months ago

Hey @mojtaba-shahverdi!

We've just dropped a new release and hope it will help resolve the issue.

Could you please update the package to @focus-reactive/sanity-plugin-inline-svg-input@1.0.1 and check if the issue still exists?

efValeron commented 1 month ago

Hey!

I have the same problem. Using version of @focus-reactive/sanity-plugin-inline-svg-input - 1.1.0

I think it has to do with next js ssr. But the component where InlineSvgPreviewComponent is rendered is client-side. If you remove InlineSvgPreviewComponent then everything works fine. But with this component there is 500 error from nextjs server

⨯ Internal error: TypeError: dompurify__WEBPACK_IMPORTED_MODULE_2__.default.sanitize is not a function
    at InlineSvgPreviewComponent (./node_modules/@focus-reactive/sanity-plugin-inline-svg-input/dist/index.esm.js:167:90)
    * lots of similar messages *
digest: "829662004"
 GET / 500 in 1402ms
 GET /_next/static/chunks/app/(site)/server-actions.js.map 404 in 42ms
chenaski commented 1 month ago

Thanks for the details @efValeron! Actually, we didn't expect this component to be included during the server build. Are you using the embedded NextStudio?

efValeron commented 1 month ago

@chenaski Yes, I'm using NextStudio. And what else I noticed, 500 error comes out only at the first page load, then it disappears and SVGs are rendered normally. But I haven't tested it in production.

chenaski commented 1 month ago

You could try adding the 'use client' directive in the route with NextStudio, because Sanity Studio is an SPA and normally it shouldn't run anything during the server build. I see the /_next/static/chunks/app/(site)/server-actions.js.map path in the error message you shared, is there anything in here that you import in/out of Sanity?

Also, could you please share your Next.js version and the Sanity schema where you use InlineSvgPreviewComponent? It would be easier for me to debug the issue. Thanks in advance!