Skip to content

Commit c76facf

Browse files
React: Avoid 'Dynamic require of react is not possible' issue
1 parent 1633942 commit c76facf

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

code/lib/react-dom-shim/src/react-16.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable react/no-deprecated */
22
import type { ReactElement } from 'react';
3-
import ReactDOM from 'react-dom';
3+
import * as ReactDOM from 'react-dom';
44

55
export const renderElement = async (node: ReactElement, el: Element) => {
66
return new Promise<null>((resolve) => {

code/lib/react-dom-shim/src/react-18.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { FC, ReactElement } from 'react';
2-
import React, { useLayoutEffect, useRef } from 'react';
2+
import * as React from 'react';
33
import type { Root as ReactRoot, RootOptions } from 'react-dom/client';
4-
import ReactDOM from 'react-dom/client';
4+
import * as ReactDOM from 'react-dom/client';
55

66
// A map of all rendered React 18 nodes
77
const nodes = new Map<Element, ReactRoot>();
@@ -11,8 +11,8 @@ const WithCallback: FC<{ callback: () => void; children: ReactElement }> = ({
1111
children,
1212
}) => {
1313
// See https://github.com/reactwg/react-18/discussions/5#discussioncomment-2276079
14-
const once = useRef<() => void>();
15-
useLayoutEffect(() => {
14+
const once = React.useRef<() => void>();
15+
React.useLayoutEffect(() => {
1616
if (once.current === callback) return;
1717
once.current = callback;
1818
callback();

code/renderers/react/src/renderToCanvas.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { global } from '@storybook/global';
22
import type { FC } from 'react';
33
import React, { Component as ReactComponent, StrictMode, Fragment } from 'react';
4-
import { renderElement, unmountElement } from '@storybook/react-dom-shim';
54

65
import type { RenderContext } from 'storybook/internal/types';
76

@@ -54,6 +53,7 @@ export async function renderToCanvas(
5453
}: RenderContext<ReactRenderer>,
5554
canvasElement: ReactRenderer['canvasElement']
5655
) {
56+
const { renderElement, unmountElement } = (await import('@storybook/react-dom-shim')).default;
5757
const Story = unboundStoryFn as FC<StoryContext<ReactRenderer>>;
5858

5959
const content = (

0 commit comments

Comments
 (0)