Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update way to check react version to switch to use react-dom/client #391

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/late-foxes-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': patch
---

Adding check react version by using major number instead string
3 changes: 2 additions & 1 deletion lib/makeWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = async (playroomConfig, options) => {
}
);
const { version } = JSON.parse(pkgContents);
isLegacyReact = !(version.startsWith('18') || version.startsWith('0.0.0'));
const majorVersion = Number(version.split('.')[0]);
isLegacyReact = !(majorVersion >= 18 || version.startsWith('0.0.0'));
} catch (e) {
throw new Error('Unable to read `react-dom` package json');
}
Expand Down
6 changes: 4 additions & 2 deletions src/Playroom/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useState, useCallback, useEffect } from 'react';
import { useRef, useContext, useState, useCallback, useEffect } from 'react';
import { useTimeoutFn } from 'react-use';
import classnames from 'classnames';
import type { PlayroomProps } from '../Playroom';
Expand Down Expand Up @@ -40,6 +40,7 @@ export default ({ themes: allThemes, widths: allWidths, snippets }: Props) => {
] = useContext(StoreContext);
const [copying, setCopying] = useState(false);
const [isReady, cancel, reset] = useTimeoutFn(() => setCopying(false), 3000);
const nodeRef = useRef(null);

const copyHandler = useCallback(() => {
dispatch({
Expand Down Expand Up @@ -157,13 +158,14 @@ export default ({ themes: allThemes, widths: allWidths, snippets }: Props) => {
</div>
<CSSTransition
in={isOpen}
nodeRef={nodeRef}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timeout={ANIMATION_TIMEOUT}
classNames={styles.transitionStyles}
mountOnEnter
unmountOnExit
onExited={() => setLastActivePanel(undefined)}
>
<div className={styles.panel} id="custom-id">
<div ref={nodeRef} className={styles.panel} id="custom-id">
{lastActivePanel === 'snippets' && (
<Snippets
isOpen={isOpen}
Expand Down
4 changes: 3 additions & 1 deletion src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import ReactDOM, { version as reactDomVersion } from 'react-dom';
// Uses the correct render API based on the available version of
// `react-dom`. This hack can be removed when support for older
// versions of React is removed.

const mainVersion = Number(reactDomVersion.split('.')[0]);
const canUseNewReactRootApi =
reactDomVersion &&
(reactDomVersion.startsWith('18') || reactDomVersion.startsWith('0.0.0'));
(mainVersion >= 18 || reactDomVersion.startsWith('0.0.0'));

export const renderElement = (node, outlet) => {
if (canUseNewReactRootApi) {
Expand Down