Skip to content

Commit 2abc1ae

Browse files
committed
fix(react-19): ensure React 19 compatibility
1 parent 2881be7 commit 2abc1ae

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

src/env/App/__snapshots__/App.spec.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`env > App renders 1`] = `
44
<DocumentFragment>
@@ -11,7 +11,7 @@ exports[`env > App renders 1`] = `
1111
</button>
1212
</div>
1313
<div
14-
id=":r0:"
14+
id="_r_0_"
1515
style="--boxColor:violet;--borderColor:purple;"
1616
>
1717
<div>

src/lib/LocalTheme/LocalRoot.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type {HTMLAttributes, ReactNode} from 'react';
2-
import {createElement, forwardRef, useEffect, useMemo} from 'react';
1+
import type {HTMLAttributes, ReactNode, ElementType} from 'react';
2+
import {forwardRef, useEffect, useMemo} from 'react';
33

44
import {createStyleObject} from '@/lib/utils';
55
import type {DataAttributes, LibraryProps} from '@/lib/NativeProps';
@@ -12,26 +12,36 @@ export type LocalRootProps = DataAttributes &
1212
LibraryProps &
1313
HTMLAttributes<HTMLElement> & {
1414
children?: ReactNode;
15-
/** Choose which HTMLElement to render as a root. div is default. */
16-
as?: string;
17-
/** Apply initial theme. */
15+
/** Choose which HTMLElement to render as a root. `div` is the default value. */
16+
as?: ElementType;
17+
/** Apply the initial theme. */
1818
theme?: Theme;
19-
/** Provide theme setter function. */
19+
/** Provide a theme setter function. */
2020
setTheme?: (arg0: Theme) => void;
2121
};
2222

2323
export const LocalRoot = forwardRef<HTMLElement, LocalRootProps>((props, ref) => {
2424
// This is needed to fix an error introduced in version 0.6.14.
2525
// Props were not transported to returned HTMLElement.
26-
const {children, as = 'div', theme = {}, setTheme = () => {}, ...restProps} = props;
26+
const {
27+
children,
28+
as: Component = 'div',
29+
theme = {},
30+
setTheme = () => {},
31+
...restProps
32+
} = props;
2733

2834
const initialStyle = useMemo(() => createStyleObject(theme), [theme]);
2935

3036
useEffect(() => {
3137
setTheme(theme);
3238
}, [theme, setTheme]);
3339

34-
return createElement(as, {...restProps, style: initialStyle, ref}, children);
40+
return (
41+
<Component ref={ref} style={initialStyle} {...restProps}>
42+
{children}
43+
</Component>
44+
);
3545
});
3646

3747
LocalRoot.displayName = 'LocalRoot';

src/lib/LocalTheme/__snapshots__/LocalRoot.spec.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`lib > LocalRoot LocalRoot - Native API accepts ref as a Mutable Object 1`] = `<div />`;
44

src/lib/LocalTheme/useLocalTheme.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {LocalRoot} from './LocalRoot';
88

99
/**
1010
* @public
11-
* React hook to apply multiple CSS variables to generated local root element (LocalRoot) and manipulate them.
12-
* Theme type is inferred from provided theme parameter.
11+
* React hook to apply multiple CSS variables to a generated local root element (LocalRoot) and manipulate them.
12+
* Theme type is inferred from the provided theme parameter.
1313
* @example
1414
* const {setTheme, getTheme, LocalRoot, getVariable, setVariable} = useLocalTheme();
1515
* const setThemeIvory = () => {
@@ -20,7 +20,7 @@ import {LocalRoot} from './LocalRoot';
2020
* return <LocalRoot theme={{foo: 'bar'}} className="demo-local">//...
2121
*/
2222
export const useLocalTheme = <TElement extends HTMLElement>() => {
23-
const themeRef = useRef<Theme>();
23+
const themeRef = useRef<Theme>({});
2424
const elementRef = useRef<TElement>(null);
2525

2626
const setTheme = useCallback((nextTheme: Theme) => {
@@ -55,13 +55,13 @@ export const useLocalTheme = <TElement extends HTMLElement>() => {
5555
return {
5656
/** Effect to apply new theme to LocalRoot */
5757
setTheme,
58-
/** Get current theme set for LocalRoot */
58+
/** Get the current theme set for LocalRoot */
5959
getTheme,
60-
/** Wrapper component which creates DOM node to store theme data */
60+
/** Wrapper component which creates a DOM node to store theme data */
6161
LocalRoot: MemoRoot,
6262
/** React Mutable Ref object attached to LocalRoot */
6363
ref: elementRef,
64-
/** Get variable value within LocalRoot theme */
64+
/** Get variable value within the LocalRoot theme */
6565
getVariable,
6666
/** Effect to set new variable value within LocalRoot theme */
6767
setVariable,

src/lib/RootTheme/useRootTheme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const useRootTheme = <TTheme extends Theme>(
5757
[id]
5858
);
5959

60+
// eslint-disable-next-line react-hooks/refs
6061
const style = useMemo(() => createStyleObject(themeRef.current), []);
6162

6263
return {

0 commit comments

Comments
 (0)