Skip to content

Commit

Permalink
fix: dynamic imports for react web components
Browse files Browse the repository at this point in the history
  • Loading branch information
BearToCode committed Aug 9, 2024
1 parent 2c9b880 commit f70ef26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/adapter-react/src/lib/MisMerge2.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@mismerge/core/web';
import type { EditorColors, Highlighter, LineDiffAlgorithm } from '@mismerge/core';
import { useEffect, useRef } from 'react';

Expand Down Expand Up @@ -41,6 +40,11 @@ export function MisMerge2({
}) {
const ref = useRef<JSX.IntrinsicElements['mis-merge2']>(null);

useEffect(() => {
// @ts-expect-error No definitions provided for web components
import('@mismerge/core/web');
}, []);

useEffect(() => {
if (ref.current) {
ref.current.highlight = highlight;
Expand Down
6 changes: 5 additions & 1 deletion packages/adapter-react/src/lib/MisMerge3.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@mismerge/core/web';
import type { EditorColors, Highlighter, LineDiffAlgorithm } from '@mismerge/core';
import { useEffect, useRef } from 'react';

Expand Down Expand Up @@ -49,6 +48,11 @@ export function MisMerge3({
}) {
const ref = useRef<JSX.IntrinsicElements['mis-merge2']>(null);

useEffect(() => {
// @ts-expect-error No definitions provided for web components
import('@mismerge/core/web');
}, []);

useEffect(() => {
if (ref.current) {
ref.current.highlight = highlight;
Expand Down

0 comments on commit f70ef26

Please sign in to comment.