Skip to content

Commit f8dcd1b

Browse files
committed
fix: resolve html-to-draftjs CJS/ESM interop error with Vite 8
Refs: PT-2037
1 parent 51daac8 commit f8dcd1b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
frame-src 'self' *.hel.fi *.hel.ninja *.youtube.com www.youtube-nocookie.com *.vimeo.com;
2626
img-src 'self' data: *.hel.fi *.hel.ninja *.ytimg.com *.youtube.com *.vimeo.com *.vimeocdn.com *.blob.core.windows.net *.hkih.hion.dev;
2727
font-src 'self' *.hel.fi *.hel.ninja;
28-
connect-src 'self' localhost:* 127.0.0.1:* *.hel.fi *.hel.ninja *.hkih.hion.dev *.digiaiiris.com;
28+
connect-src 'self' localhost:* 127.0.0.1:* *.hel.fi *.hel.ninja *.hkih.hion.dev *.digiaiiris.com *.sentry.io;
2929
manifest-src 'self';
3030
base-uri 'self';
3131
form-action 'self';

src/common/components/textEditor/TextEditor.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';
1414
import classNames from 'classnames';
1515
import { ContentState, convertToRaw, EditorState } from 'draft-js';
1616
import draftToHtml from 'draftjs-to-html';
17-
import htmlToDraft from 'html-to-draftjs';
17+
import htmlToDraftImport from 'html-to-draftjs';
1818
import React from 'react';
1919
import { Editor, EditorState as EditorStateWysiwyg } from 'react-draft-wysiwyg';
2020
import { useTranslation } from 'react-i18next';
@@ -24,6 +24,13 @@ import styles from './textEditor.module.scss';
2424
import useIsMounted from '../../../hooks/useIsMounted';
2525
import InputWrapper, { InputWrapperProps } from '../inputWrapper/InputWrapper';
2626

27+
// Vite 8 CJS/ESM interop: html-to-draftjs uses module.exports, unwrap .default if needed
28+
const htmlToDraft: typeof htmlToDraftImport =
29+
typeof htmlToDraftImport === 'function'
30+
? htmlToDraftImport
31+
: (htmlToDraftImport as unknown as { default: typeof htmlToDraftImport })
32+
.default;
33+
2734
const convertHtmlToEditorState = (html: string) => {
2835
const blocksFromHtml = htmlToDraft(html);
2936
const { contentBlocks, entityMap } = blocksFromHtml;

0 commit comments

Comments
 (0)