Skip to content

Commit

Permalink
React: Avoid 'Dynamic require of react is not possible' issue
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Jul 28, 2024
1 parent 1633942 commit 1991726
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion code/lib/react-dom-shim/src/react-16.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/no-deprecated */
import type { ReactElement } from 'react';
import ReactDOM from 'react-dom';
import * as ReactDOM from 'react-dom';

export const renderElement = async (node: ReactElement, el: Element) => {
return new Promise<null>((resolve) => {
Expand Down
8 changes: 4 additions & 4 deletions code/lib/react-dom-shim/src/react-18.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FC, ReactElement } from 'react';
import React, { useLayoutEffect, useRef } from 'react';
import * as React from 'react';
import type { Root as ReactRoot, RootOptions } from 'react-dom/client';
import ReactDOM from 'react-dom/client';
import * as ReactDOM from 'react-dom/client';

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

0 comments on commit 1991726

Please sign in to comment.