Skip to content

Commit

Permalink
Revert dynamic import of react-dom-shim
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Jul 29, 2024
1 parent 8f30c5c commit 11f43cc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
6 changes: 3 additions & 3 deletions code/addons/docs/src/DocsRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PropsWithChildren } from 'react';
import React, { Component } from 'react';
import ReactDomShim from '@storybook/react-dom-shim';
import { renderElement, unmountElement } from '@storybook/react-dom-shim';
import type {
Renderer,
Parameters,
Expand Down Expand Up @@ -62,7 +62,7 @@ export class DocsRenderer<TRenderer extends Renderer> {
import('@mdx-js/react')
.then(({ MDXProvider }) =>
// We use a `key={}` here to reset the `hasError` state each time we render ErrorBoundary
ReactDomShim.renderElement(
renderElement(
<ErrorBoundary showException={reject} key={Math.random()}>
<MDXProvider components={components}>
<TDocs context={context} docsParameter={docsParameter} />
Expand All @@ -76,7 +76,7 @@ export class DocsRenderer<TRenderer extends Renderer> {
};

this.unmount = (element: HTMLElement) => {
ReactDomShim.unmountElement(element);
unmountElement(element);
};
}
}
6 changes: 2 additions & 4 deletions code/lib/react-dom-shim/src/react-16.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import type { ReactElement } from 'react';
import * as ReactDOM from 'react-dom';

const renderElement = async (node: ReactElement, el: Element) => {
export const renderElement = async (node: ReactElement, el: Element) => {
return new Promise<null>((resolve) => {
ReactDOM.render(node, el, () => resolve(null));
});
};

const unmountElement = (el: Element) => {
export const unmountElement = (el: Element) => {
ReactDOM.unmountComponentAtNode(el);
};

export default { renderElement, unmountElement };
6 changes: 2 additions & 4 deletions code/lib/react-dom-shim/src/react-18.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const WithCallback: FC<{ callback: () => void; children: ReactElement }> = ({
return children;
};

const renderElement = async (node: ReactElement, el: Element, rootOptions?: RootOptions) => {
export const renderElement = async (node: ReactElement, el: Element, rootOptions?: RootOptions) => {
// Create Root Element conditionally for new React 18 Root Api
const root = await getReactRoot(el, rootOptions);

Expand All @@ -30,7 +30,7 @@ const renderElement = async (node: ReactElement, el: Element, rootOptions?: Root
});
};

const unmountElement = (el: Element, shouldUseNewRootApi?: boolean) => {
export const unmountElement = (el: Element, shouldUseNewRootApi?: boolean) => {
const root = nodes.get(el);

if (root) {
Expand All @@ -49,5 +49,3 @@ const getReactRoot = async (el: Element, rootOptions?: RootOptions): Promise<Rea

return root;
};

export default { renderElement, unmountElement };
2 changes: 1 addition & 1 deletion code/renderers/react/src/renderToCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function renderToCanvas(
}: RenderContext<ReactRenderer>,
canvasElement: ReactRenderer['canvasElement']
) {
const { renderElement, unmountElement } = (await import('@storybook/react-dom-shim')).default;
const { renderElement, unmountElement } = await import('@storybook/react-dom-shim');
const Story = unboundStoryFn as FC<StoryContext<ReactRenderer>>;

const content = (
Expand Down

0 comments on commit 11f43cc

Please sign in to comment.