Skip to content

Commit

Permalink
Remove dom purify to reduce bundle size (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilkowalski committed Jun 8, 2024
1 parent ccf7a3e commit bb37103
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@types/dompurify": "^3.0.5",
"@types/node": "^18.11.13",
"@types/react": "^18.0.26",
"dompurify": "^3.0.9",
"prettier": "^2.8.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
4 changes: 1 addition & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 6 additions & 16 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import React from 'react';
import ReactDOM from 'react-dom';

import DOMPurify from 'dompurify';
import { getAsset, Loader } from './assets';
import { useIsDocumentHidden } from './hooks';
import { toast, ToastState } from './state';
Expand Down Expand Up @@ -250,10 +249,6 @@ const Toast = (props: ToastProps) => {
return <Loader visible={toastType === 'loading'} />;
}

function sanitizeHTML(html: string): { __html: string } {
return { __html: DOMPurify.sanitize(html) };
}

return (
<li
aria-live={toast.important ? 'assertive' : 'polite'}
Expand Down Expand Up @@ -391,11 +386,9 @@ const Toast = (props: ToastProps) => {
) : null}

<div data-content="" className={cn(classNames?.content, toast?.classNames?.content)}>
<div
data-title=""
className={cn(classNames?.title, toast?.classNames?.title)}
dangerouslySetInnerHTML={sanitizeHTML(toast.title as string)}
></div>
<div data-title="" className={cn(classNames?.title, toast?.classNames?.title)}>
{toast.title}
</div>
{toast.description ? (
<div
data-description=""
Expand All @@ -404,12 +397,9 @@ const Toast = (props: ToastProps) => {
toastDescriptionClassname,
classNames?.description,
toast?.classNames?.description,
)}
dangerouslySetInnerHTML={
typeof toast.description === 'string' ? sanitizeHTML(toast.description as string) : undefined
}
)}
>
{typeof toast.description === 'object' ? toast.description : null}
{toast.description}
</div>
) : null}
</div>
Expand Down Expand Up @@ -437,7 +427,7 @@ const Toast = (props: ToastProps) => {
) : toast.action && isAction(toast.action) ? (
<button
data-button
data-action
data-action
style={toast.actionButtonStyle || actionButtonStyle}
onClick={(event) => {
// We need to check twice because typescript
Expand Down

0 comments on commit bb37103

Please sign in to comment.