@niibase/uniwind 1.1.10 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ function useStyle(componentOrClassName, classNameOrComponentProps, componentProp
24
24
  const componentProps = isComponentOverload ? componentPropsOrState : classNameOrComponentProps;
25
25
  const actualState = isComponentOverload ? state : componentPropsOrState;
26
26
  const styleState = className ? _native.UniwindStore.getStyles(className, componentProps, actualState) : emptyState;
27
- (0, _react.useEffect)(() => {
27
+ (0, _react.useLayoutEffect)(() => {
28
28
  if (__DEV__ || styleState.dependencies.length > 0) {
29
29
  const dispose = _listener.UniwindListener.subscribe(rerender, styleState.dependencies);
30
30
  return dispose;
@@ -46,7 +46,7 @@ const withAutoUniwind = Component2 => props => {
46
46
  classNames: ""
47
47
  });
48
48
  const [, rerender] = (0, _react.useReducer)(() => ({}), {});
49
- (0, _react.useEffect)(() => {
49
+ (0, _react.useLayoutEffect)(() => {
50
50
  const dispose = _web.CSSListener.subscribeToClassName(classNames, rerender);
51
51
  return dispose;
52
52
  }, [classNames]);
@@ -84,7 +84,7 @@ const withManualUniwind = (Component2, options) => props => {
84
84
  classNames: ""
85
85
  });
86
86
  const [, rerender] = (0, _react.useReducer)(() => ({}), {});
87
- (0, _react.useEffect)(() => {
87
+ (0, _react.useLayoutEffect)(() => {
88
88
  const dispose = _web.CSSListener.subscribeToClassName(classNames, rerender);
89
89
  return dispose;
90
90
  }, [classNames]);
@@ -50,12 +50,15 @@ const withAutoUniwind = Component2 => props => {
50
50
  generatedProps: {},
51
51
  dependencies: []
52
52
  });
53
- const deps = Array.from(new Set(dependencies));
53
+ const dependencySum = dependencies.reduce((acc, dependency) => {
54
+ acc |= 1 << dependency;
55
+ return acc;
56
+ }, 0);
54
57
  const [, rerender] = (0, _react.useReducer)(() => ({}), {});
55
- (0, _react.useEffect)(() => {
56
- const dispose = _listener.UniwindListener.subscribe(rerender, deps);
58
+ (0, _react.useLayoutEffect)(() => {
59
+ const dispose = _listener.UniwindListener.subscribe(rerender, Array.from(new Set(dependencies)));
57
60
  return dispose;
58
- }, [deps]);
61
+ }, [dependencySum]);
59
62
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(Component2, {
60
63
  ...props,
61
64
  ...generatedProps
@@ -86,19 +89,31 @@ const withManualUniwind = (Component2, options) => props => {
86
89
  styles,
87
90
  dependencies: dependencies2
88
91
  } = _native.UniwindStore.getStyles(className);
89
- acc.generatedProps[propName] = styles;
90
92
  acc.dependencies.push(...dependencies2);
93
+ if (!(0, _withUniwindUtils.isStyleProperty)(propName)) {
94
+ acc.generatedProps[propName] = styles;
95
+ return acc;
96
+ }
97
+ const existingStyle = props[propName];
98
+ if (existingStyle) {
99
+ acc.generatedProps[propName] = [styles, existingStyle];
100
+ return acc;
101
+ }
102
+ acc.generatedProps[propName] = styles;
91
103
  return acc;
92
104
  }, {
93
105
  generatedProps: {},
94
106
  dependencies: []
95
107
  });
96
- const deps = Array.from(new Set(dependencies));
108
+ const dependencySum = dependencies.reduce((acc, dependency) => {
109
+ acc |= 1 << dependency;
110
+ return acc;
111
+ }, 0);
97
112
  const [, rerender] = (0, _react.useReducer)(() => ({}), {});
98
- (0, _react.useEffect)(() => {
99
- const dispose = _listener.UniwindListener.subscribe(rerender, deps);
113
+ (0, _react.useLayoutEffect)(() => {
114
+ const dispose = _listener.UniwindListener.subscribe(rerender, Array.from(new Set(dependencies)));
100
115
  return dispose;
101
- }, [deps]);
116
+ }, [dependencySum]);
102
117
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(Component2, {
103
118
  ...props,
104
119
  ...generatedProps
@@ -24,7 +24,7 @@ const logDevError = name => {
24
24
  const useCSSVariable = name => {
25
25
  const [value, setValue] = (0, _react.useState)(getValue(name));
26
26
  const nameRef = (0, _react.useRef)(name);
27
- (0, _react.useEffect)(() => {
27
+ (0, _react.useLayoutEffect)(() => {
28
28
  if (Array.isArray(name) && Array.isArray(nameRef.current)) {
29
29
  if (arrayEquals(name, nameRef.current)) {
30
30
  return;
@@ -38,7 +38,7 @@ const useCSSVariable = name => {
38
38
  nameRef.current = name;
39
39
  }
40
40
  }, [name]);
41
- (0, _react.useEffect)(() => {
41
+ (0, _react.useLayoutEffect)(() => {
42
42
  const updateValue = () => setValue(getValue(nameRef.current));
43
43
  const dispose = _listener.UniwindListener.subscribe(updateValue, [_types.StyleDependency.Theme, _types.StyleDependency.Variables]);
44
44
  return dispose;
@@ -9,7 +9,7 @@ var _web = require("../core/web");
9
9
  const emptyState = {};
10
10
  const useResolveClassNames = className => {
11
11
  const [styles, recreate] = (0, _react.useReducer)(() => className !== "" ? (0, _web.getWebStyles)(className) : emptyState, className !== "" ? (0, _web.getWebStyles)(className) : emptyState);
12
- (0, _react.useEffect)(() => {
12
+ (0, _react.useLayoutEffect)(() => {
13
13
  if (className === "") {
14
14
  return;
15
15
  }
@@ -9,17 +9,17 @@ var _listener = require("../core/listener");
9
9
  var _native = require("../core/native");
10
10
  const useResolveClassNames = className => {
11
11
  const [uniwindState, recreate] = (0, _react.useReducer)(() => _native.UniwindStore.getStyles(className), _native.UniwindStore.getStyles(className));
12
- (0, _react.useEffect)(() => {
12
+ (0, _react.useLayoutEffect)(() => {
13
13
  if (className !== "") {
14
14
  recreate();
15
15
  }
16
16
  }, [className]);
17
- (0, _react.useEffect)(() => {
17
+ (0, _react.useLayoutEffect)(() => {
18
18
  if (uniwindState.dependencies.length > 0) {
19
19
  const dispose = _listener.UniwindListener.subscribe(recreate, uniwindState.dependencies);
20
20
  return dispose;
21
21
  }
22
- }, [uniwindState.dependencies, className]);
22
+ }, [uniwindState.dependencySum, className]);
23
23
  return uniwindState.styles;
24
24
  };
25
25
  exports.useResolveClassNames = useResolveClassNames;
@@ -11,7 +11,7 @@ var _types = require("../types");
11
11
  const useUniwind = () => {
12
12
  const [theme, setTheme] = (0, _react.useState)(_core.Uniwind.currentTheme);
13
13
  const [hasAdaptiveThemes, setHasAdaptiveThemes] = (0, _react.useState)(_core.Uniwind.hasAdaptiveThemes);
14
- (0, _react.useEffect)(() => {
14
+ (0, _react.useLayoutEffect)(() => {
15
15
  const dispose = _listener.UniwindListener.subscribe(() => {
16
16
  setTheme(_core.Uniwind.currentTheme);
17
17
  setHasAdaptiveThemes(_core.Uniwind.hasAdaptiveThemes);
@@ -25,6 +25,14 @@ const uniwind = ({
25
25
  const stringifiedThemes = (0, _stringifyThemes.stringifyThemes)(themes);
26
26
  return {
27
27
  name: "uniwind",
28
+ enforce: "pre",
29
+ resolveId: (source, importer) => {
30
+ const normalizedSource = (0, _node.normalizePath)(source);
31
+ const isTarget = source === "./createOrderedCSSStyleSheet" || normalizedSource.endsWith("react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js");
32
+ if (isTarget && importer !== void 0 && (0, _node.normalizePath)(importer).includes("react-native-web/dist/exports/StyleSheet")) {
33
+ return styleSheetPath;
34
+ }
35
+ },
28
36
  config: () => ({
29
37
  css: {
30
38
  transformer: "lightningcss",
@@ -1,4 +1,4 @@
1
- import { useEffect, useReducer } from "react";
1
+ import { useLayoutEffect, useReducer } from "react";
2
2
  import { createAnimatedComponent } from "react-native-reanimated";
3
3
  import { UniwindListener } from "../../core/listener.js";
4
4
  import { UniwindStore } from "../../core/native/index.js";
@@ -16,7 +16,7 @@ export function useStyle(componentOrClassName, classNameOrComponentProps, compon
16
16
  const componentProps = isComponentOverload ? componentPropsOrState : classNameOrComponentProps;
17
17
  const actualState = isComponentOverload ? state : componentPropsOrState;
18
18
  const styleState = className ? UniwindStore.getStyles(className, componentProps, actualState) : emptyState;
19
- useEffect(() => {
19
+ useLayoutEffect(() => {
20
20
  if (__DEV__ || styleState.dependencies.length > 0) {
21
21
  const dispose = UniwindListener.subscribe(rerender, styleState.dependencies);
22
22
  return dispose;
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useEffect, useReducer } from "react";
2
+ import { useLayoutEffect, useReducer } from "react";
3
3
  import { CSSListener, formatColor, getWebStyles } from "../core/web/index.js";
4
4
  import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from "./withUniwindUtils.js";
5
5
  export const withUniwind = (Component2, options) => options ? withManualUniwind(Component2, options) : withAutoUniwind(Component2);
@@ -30,7 +30,7 @@ const withAutoUniwind = (Component2) => (props) => {
30
30
  return acc;
31
31
  }, { generatedProps: {}, classNames: "" });
32
32
  const [, rerender] = useReducer(() => ({}), {});
33
- useEffect(() => {
33
+ useLayoutEffect(() => {
34
34
  const dispose = CSSListener.subscribeToClassName(classNames, rerender);
35
35
  return dispose;
36
36
  }, [classNames]);
@@ -62,7 +62,7 @@ const withManualUniwind = (Component2, options) => (props) => {
62
62
  return acc;
63
63
  }, { generatedProps: {}, classNames: "" });
64
64
  const [, rerender] = useReducer(() => ({}), {});
65
- useEffect(() => {
65
+ useLayoutEffect(() => {
66
66
  const dispose = CSSListener.subscribeToClassName(classNames, rerender);
67
67
  return dispose;
68
68
  }, [classNames]);
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useEffect, useReducer } from "react";
2
+ import { useLayoutEffect, useReducer } from "react";
3
3
  import { UniwindListener } from "../core/listener.js";
4
4
  import { UniwindStore } from "../core/native/index.js";
5
5
  import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from "./withUniwindUtils.js";
@@ -31,12 +31,15 @@ const withAutoUniwind = (Component2) => (props) => {
31
31
  }
32
32
  return acc;
33
33
  }, { generatedProps: {}, dependencies: [] });
34
- const deps = Array.from(new Set(dependencies));
34
+ const dependencySum = dependencies.reduce((acc, dependency) => {
35
+ acc |= 1 << dependency;
36
+ return acc;
37
+ }, 0);
35
38
  const [, rerender] = useReducer(() => ({}), {});
36
- useEffect(() => {
37
- const dispose = UniwindListener.subscribe(rerender, deps);
39
+ useLayoutEffect(() => {
40
+ const dispose = UniwindListener.subscribe(rerender, Array.from(new Set(dependencies)));
38
41
  return dispose;
39
- }, [deps]);
42
+ }, [dependencySum]);
40
43
  return /* @__PURE__ */ jsx(
41
44
  Component2,
42
45
  {
@@ -61,16 +64,28 @@ const withManualUniwind = (Component2, options) => (props) => {
61
64
  return acc;
62
65
  }
63
66
  const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(className);
64
- acc.generatedProps[propName] = styles;
65
67
  acc.dependencies.push(...dependencies2);
68
+ if (!isStyleProperty(propName)) {
69
+ acc.generatedProps[propName] = styles;
70
+ return acc;
71
+ }
72
+ const existingStyle = props[propName];
73
+ if (existingStyle) {
74
+ acc.generatedProps[propName] = [styles, existingStyle];
75
+ return acc;
76
+ }
77
+ acc.generatedProps[propName] = styles;
66
78
  return acc;
67
79
  }, { generatedProps: {}, dependencies: [] });
68
- const deps = Array.from(new Set(dependencies));
80
+ const dependencySum = dependencies.reduce((acc, dependency) => {
81
+ acc |= 1 << dependency;
82
+ return acc;
83
+ }, 0);
69
84
  const [, rerender] = useReducer(() => ({}), {});
70
- useEffect(() => {
71
- const dispose = UniwindListener.subscribe(rerender, deps);
85
+ useLayoutEffect(() => {
86
+ const dispose = UniwindListener.subscribe(rerender, Array.from(new Set(dependencies)));
72
87
  return dispose;
73
- }, [deps]);
88
+ }, [dependencySum]);
74
89
  return /* @__PURE__ */ jsx(
75
90
  Component2,
76
91
  {
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef, useState } from "react";
1
+ import { useLayoutEffect, useRef, useState } from "react";
2
2
  import { UniwindListener } from "../../core/listener.js";
3
3
  import { Logger } from "../../core/logger.js";
4
4
  import { StyleDependency } from "../../types.js";
@@ -20,7 +20,7 @@ const logDevError = (name) => {
20
20
  export const useCSSVariable = (name) => {
21
21
  const [value, setValue] = useState(getValue(name));
22
22
  const nameRef = useRef(name);
23
- useEffect(() => {
23
+ useLayoutEffect(() => {
24
24
  if (Array.isArray(name) && Array.isArray(nameRef.current)) {
25
25
  if (arrayEquals(name, nameRef.current)) {
26
26
  return;
@@ -34,7 +34,7 @@ export const useCSSVariable = (name) => {
34
34
  nameRef.current = name;
35
35
  }
36
36
  }, [name]);
37
- useEffect(() => {
37
+ useLayoutEffect(() => {
38
38
  const updateValue = () => setValue(getValue(nameRef.current));
39
39
  const dispose = UniwindListener.subscribe(
40
40
  updateValue,
@@ -1,4 +1,4 @@
1
- import { useEffect, useReducer } from "react";
1
+ import { useLayoutEffect, useReducer } from "react";
2
2
  import { CSSListener, getWebStyles } from "../core/web/index.js";
3
3
  const emptyState = {};
4
4
  export const useResolveClassNames = (className) => {
@@ -6,7 +6,7 @@ export const useResolveClassNames = (className) => {
6
6
  () => className !== "" ? getWebStyles(className) : emptyState,
7
7
  className !== "" ? getWebStyles(className) : emptyState
8
8
  );
9
- useEffect(() => {
9
+ useLayoutEffect(() => {
10
10
  if (className === "") {
11
11
  return;
12
12
  }
@@ -1,4 +1,4 @@
1
- import { useEffect, useReducer } from "react";
1
+ import { useLayoutEffect, useReducer } from "react";
2
2
  import { UniwindListener } from "../core/listener.js";
3
3
  import { UniwindStore } from "../core/native/index.js";
4
4
  export const useResolveClassNames = (className) => {
@@ -6,16 +6,16 @@ export const useResolveClassNames = (className) => {
6
6
  () => UniwindStore.getStyles(className),
7
7
  UniwindStore.getStyles(className)
8
8
  );
9
- useEffect(() => {
9
+ useLayoutEffect(() => {
10
10
  if (className !== "") {
11
11
  recreate();
12
12
  }
13
13
  }, [className]);
14
- useEffect(() => {
14
+ useLayoutEffect(() => {
15
15
  if (uniwindState.dependencies.length > 0) {
16
16
  const dispose = UniwindListener.subscribe(recreate, uniwindState.dependencies);
17
17
  return dispose;
18
18
  }
19
- }, [uniwindState.dependencies, className]);
19
+ }, [uniwindState.dependencySum, className]);
20
20
  return uniwindState.styles;
21
21
  };
@@ -1,11 +1,11 @@
1
- import { useEffect, useState } from "react";
1
+ import { useLayoutEffect, useState } from "react";
2
2
  import { Uniwind } from "../core/index.js";
3
3
  import { UniwindListener } from "../core/listener.js";
4
4
  import { StyleDependency } from "../types.js";
5
5
  export const useUniwind = () => {
6
6
  const [theme, setTheme] = useState(Uniwind.currentTheme);
7
7
  const [hasAdaptiveThemes, setHasAdaptiveThemes] = useState(Uniwind.hasAdaptiveThemes);
8
- useEffect(() => {
8
+ useLayoutEffect(() => {
9
9
  const dispose = UniwindListener.subscribe(() => {
10
10
  setTheme(Uniwind.currentTheme);
11
11
  setHasAdaptiveThemes(Uniwind.hasAdaptiveThemes);
@@ -28,6 +28,14 @@ export const uniwind = ({
28
28
  const stringifiedThemes = stringifyThemes(themes);
29
29
  return {
30
30
  name: "uniwind",
31
+ enforce: "pre",
32
+ resolveId: (source, importer) => {
33
+ const normalizedSource = normalizePath(source);
34
+ const isTarget = source === "./createOrderedCSSStyleSheet" || normalizedSource.endsWith("react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js");
35
+ if (isTarget && importer !== void 0 && normalizePath(importer).includes("react-native-web/dist/exports/StyleSheet")) {
36
+ return styleSheetPath;
37
+ }
38
+ },
31
39
  config: () => ({
32
40
  css: {
33
41
  transformer: "lightningcss",
@@ -33,6 +33,14 @@ const uniwind = ({
33
33
  const stringifiedThemes = stringifyThemes.stringifyThemes(themes);
34
34
  return {
35
35
  name: "uniwind",
36
+ enforce: "pre",
37
+ resolveId: (source, importer) => {
38
+ const normalizedSource = node.normalizePath(source);
39
+ const isTarget = source === "./createOrderedCSSStyleSheet" || normalizedSource.endsWith("react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js");
40
+ if (isTarget && importer !== void 0 && node.normalizePath(importer).includes("react-native-web/dist/exports/StyleSheet")) {
41
+ return styleSheetPath;
42
+ }
43
+ },
36
44
  config: () => ({
37
45
  css: {
38
46
  transformer: "lightningcss",
@@ -27,6 +27,14 @@ const uniwind = ({
27
27
  const stringifiedThemes = stringifyThemes(themes);
28
28
  return {
29
29
  name: "uniwind",
30
+ enforce: "pre",
31
+ resolveId: (source, importer) => {
32
+ const normalizedSource = normalizePath(source);
33
+ const isTarget = source === "./createOrderedCSSStyleSheet" || normalizedSource.endsWith("react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js");
34
+ if (isTarget && importer !== void 0 && normalizePath(importer).includes("react-native-web/dist/exports/StyleSheet")) {
35
+ return styleSheetPath;
36
+ }
37
+ },
30
38
  config: () => ({
31
39
  css: {
32
40
  transformer: "lightningcss",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@niibase/uniwind",
4
- "version": "1.1.10",
4
+ "version": "1.1.11",
5
5
  "description": "The fastest Tailwind bindings for React Native with Reanimated 4 support",
6
6
  "homepage": "https://uniwind.dev",
7
7
  "author": "Unistack",
@@ -19,7 +19,8 @@
19
19
  "circular:check": "dpdm --no-warning --no-tree -T --exit-code circular:1 'src/**/*.ts' 'src/**/*.tsx'",
20
20
  "build:css": "bun run src/css/index.ts",
21
21
  "postinstall": "node scripts/postinstall.mjs",
22
- "test": "jest"
22
+ "test:native": "jest --config jest.config.native.js",
23
+ "test:web": "jest --config jest.config.web.js"
23
24
  },
24
25
  "keywords": [
25
26
  "unistyles",
@@ -55,7 +56,6 @@
55
56
  },
56
57
  "./metro": {
57
58
  "types": "./dist/metro/index.d.ts",
58
- "import": "./dist/metro/index.mjs",
59
59
  "default": "./dist/metro/index.cjs"
60
60
  },
61
61
  "./vite": {
@@ -92,23 +92,28 @@
92
92
  "tailwindcss": ">=4"
93
93
  },
94
94
  "devDependencies": {
95
+ "@react-native/babel-preset": "0.83.0",
96
+ "@testing-library/jest-dom": "6.9.1",
97
+ "@testing-library/jest-native": "5.4.3",
98
+ "@testing-library/react": "16.3.2",
99
+ "@testing-library/react-native": "13.3.3",
95
100
  "@types/bun": "catalog:",
96
101
  "@types/culori": "4.0.1",
102
+ "@types/jest": "30.0.0",
97
103
  "@types/react": "catalog:",
98
- "react-native-reanimated": "catalog:",
99
- "typescript": "catalog:",
100
104
  "metro": "0.83.3",
101
105
  "dpdm": "3.14.0",
102
- "unbuild": "3.6.1",
103
- "vite": "7.2.7",
104
106
  "jest": "30.2.0",
107
+ "jest-environment-jsdom": "30.2.0",
108
+ "prettier": "3.7.4",
105
109
  "react-native-gesture-handler": "2.28.0",
110
+ "react-native-reanimated": "catalog:",
106
111
  "react-native-safe-area-context": "5.6.0",
112
+ "react-native-web": "catalog:",
107
113
  "react-test-renderer": "19.1.0",
108
- "@react-native/babel-preset": "0.83.0",
109
- "@testing-library/jest-native": "5.4.3",
110
- "@testing-library/react-native": "13.3.3",
111
- "prettier": "3.7.4",
112
- "@types/jest": "30.0.0"
114
+ "ts-jest": "29.4.6",
115
+ "typescript": "catalog:",
116
+ "unbuild": "3.6.1",
117
+ "vite": "7.2.7"
113
118
  }
114
119
  }
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/strict-boolean-expressions */
2
2
  /* eslint-disable prefer-arrow/prefer-arrow-functions */
3
- import { ComponentType, useEffect, useReducer } from 'react'
3
+ import { ComponentType, useLayoutEffect, useReducer } from 'react'
4
4
  import { createAnimatedComponent } from 'react-native-reanimated'
5
5
  import { UniwindListener } from '../../core/listener'
6
6
  import { UniwindStore } from '../../core/native'
@@ -47,7 +47,7 @@ export function useStyle<T extends React.ComponentType<any>>(
47
47
  ? UniwindStore.getStyles(className, componentProps, actualState)
48
48
  : emptyState
49
49
 
50
- useEffect(() => {
50
+ useLayoutEffect(() => {
51
51
  if (__DEV__ || styleState.dependencies.length > 0) {
52
52
  const dispose = UniwindListener.subscribe(rerender, styleState.dependencies)
53
53
 
@@ -1,4 +1,4 @@
1
- import { ComponentProps, useEffect, useReducer } from 'react'
1
+ import { ComponentProps, useLayoutEffect, useReducer } from 'react'
2
2
  import { UniwindListener } from '../core/listener'
3
3
  import { UniwindStore } from '../core/native'
4
4
  import { StyleDependency } from '../types'
@@ -53,14 +53,17 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
53
53
  return acc
54
54
  }, { generatedProps: {} as AnyObject, dependencies: [] as Array<StyleDependency> })
55
55
 
56
- const deps = Array.from(new Set(dependencies))
56
+ const dependencySum = dependencies.reduce((acc, dependency) => {
57
+ acc |= 1 << dependency
58
+ return acc
59
+ }, 0)
57
60
  const [, rerender] = useReducer(() => ({}), {})
58
61
 
59
- useEffect(() => {
60
- const dispose = UniwindListener.subscribe(rerender, deps)
62
+ useLayoutEffect(() => {
63
+ const dispose = UniwindListener.subscribe(rerender, Array.from(new Set(dependencies)))
61
64
 
62
65
  return dispose
63
- }, [deps])
66
+ }, [dependencySum])
64
67
 
65
68
  return (
66
69
  <Component
@@ -93,21 +96,39 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
93
96
  }
94
97
 
95
98
  const { styles, dependencies } = UniwindStore.getStyles(className)
99
+ acc.dependencies.push(...dependencies)
100
+
101
+ if (!isStyleProperty(propName)) {
102
+ acc.generatedProps[propName] = styles
103
+
104
+ return acc
105
+ }
106
+
107
+ const existingStyle = props[propName]
108
+
109
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
110
+ if (existingStyle) {
111
+ acc.generatedProps[propName] = [styles, existingStyle]
112
+
113
+ return acc
114
+ }
96
115
 
97
116
  acc.generatedProps[propName] = styles
98
- acc.dependencies.push(...dependencies)
99
117
 
100
118
  return acc
101
119
  }, { generatedProps: {} as AnyObject, dependencies: [] as Array<StyleDependency> })
102
120
 
103
- const deps = Array.from(new Set(dependencies))
121
+ const dependencySum = dependencies.reduce((acc, dependency) => {
122
+ acc |= 1 << dependency
123
+ return acc
124
+ }, 0)
104
125
  const [, rerender] = useReducer(() => ({}), {})
105
126
 
106
- useEffect(() => {
107
- const dispose = UniwindListener.subscribe(rerender, deps)
127
+ useLayoutEffect(() => {
128
+ const dispose = UniwindListener.subscribe(rerender, Array.from(new Set(dependencies)))
108
129
 
109
130
  return dispose
110
- }, [deps])
131
+ }, [dependencySum])
111
132
 
112
133
  return (
113
134
  <Component
@@ -1,4 +1,4 @@
1
- import { ComponentProps, useEffect, useReducer } from 'react'
1
+ import { ComponentProps, useLayoutEffect, useReducer } from 'react'
2
2
  import { CSSListener, formatColor, getWebStyles } from '../core/web'
3
3
  import { AnyObject, Component, OptionMapping, WithUniwind } from './types'
4
4
  import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from './withUniwindUtils'
@@ -54,7 +54,7 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
54
54
 
55
55
  const [, rerender] = useReducer(() => ({}), {})
56
56
 
57
- useEffect(() => {
57
+ useLayoutEffect(() => {
58
58
  const dispose = CSSListener.subscribeToClassName(classNames, rerender)
59
59
 
60
60
  return dispose
@@ -100,7 +100,7 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
100
100
 
101
101
  const [, rerender] = useReducer(() => ({}), {})
102
102
 
103
- useEffect(() => {
103
+ useLayoutEffect(() => {
104
104
  const dispose = CSSListener.subscribeToClassName(classNames, rerender)
105
105
 
106
106
  return dispose
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef, useState } from 'react'
1
+ import { useLayoutEffect, useRef, useState } from 'react'
2
2
  import { UniwindListener } from '../../core/listener'
3
3
  import { Logger } from '../../core/logger'
4
4
  import { StyleDependency } from '../../types'
@@ -45,7 +45,7 @@ export const useCSSVariable: UseCSSVariable = (name: string | Array<string>) =>
45
45
  const [value, setValue] = useState(getValue(name))
46
46
  const nameRef = useRef(name)
47
47
 
48
- useEffect(() => {
48
+ useLayoutEffect(() => {
49
49
  if (Array.isArray(name) && Array.isArray(nameRef.current)) {
50
50
  if (arrayEquals(name, nameRef.current)) {
51
51
  return
@@ -63,7 +63,7 @@ export const useCSSVariable: UseCSSVariable = (name: string | Array<string>) =>
63
63
  }
64
64
  }, [name])
65
65
 
66
- useEffect(() => {
66
+ useLayoutEffect(() => {
67
67
  const updateValue = () => setValue(getValue(nameRef.current))
68
68
  const dispose = UniwindListener.subscribe(
69
69
  updateValue,
@@ -1,4 +1,4 @@
1
- import { useEffect, useReducer } from 'react'
1
+ import { useLayoutEffect, useReducer } from 'react'
2
2
  import { UniwindListener } from '../core/listener'
3
3
  import { UniwindStore } from '../core/native'
4
4
 
@@ -8,19 +8,19 @@ export const useResolveClassNames = (className: string) => {
8
8
  UniwindStore.getStyles(className),
9
9
  )
10
10
 
11
- useEffect(() => {
11
+ useLayoutEffect(() => {
12
12
  if (className !== '') {
13
13
  recreate()
14
14
  }
15
15
  }, [className])
16
16
 
17
- useEffect(() => {
17
+ useLayoutEffect(() => {
18
18
  if (uniwindState.dependencies.length > 0) {
19
19
  const dispose = UniwindListener.subscribe(recreate, uniwindState.dependencies)
20
20
 
21
21
  return dispose
22
22
  }
23
- }, [uniwindState.dependencies, className])
23
+ }, [uniwindState.dependencySum, className])
24
24
 
25
25
  return uniwindState.styles
26
26
  }
@@ -1,4 +1,4 @@
1
- import { useEffect, useReducer } from 'react'
1
+ import { useLayoutEffect, useReducer } from 'react'
2
2
  import { RNStyle } from '../core/types'
3
3
  import { CSSListener, getWebStyles } from '../core/web'
4
4
 
@@ -10,7 +10,7 @@ export const useResolveClassNames = (className: string) => {
10
10
  className !== '' ? getWebStyles(className) : emptyState,
11
11
  )
12
12
 
13
- useEffect(() => {
13
+ useLayoutEffect(() => {
14
14
  if (className === '') {
15
15
  return
16
16
  }
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from 'react'
1
+ import { useLayoutEffect, useState } from 'react'
2
2
  import { Uniwind } from '../core'
3
3
  import { UniwindListener } from '../core/listener'
4
4
  import { ThemeName } from '../core/types'
@@ -8,7 +8,7 @@ export const useUniwind = () => {
8
8
  const [theme, setTheme] = useState(Uniwind.currentTheme)
9
9
  const [hasAdaptiveThemes, setHasAdaptiveThemes] = useState(Uniwind.hasAdaptiveThemes)
10
10
 
11
- useEffect(() => {
11
+ useLayoutEffect(() => {
12
12
  const dispose = UniwindListener.subscribe(() => {
13
13
  setTheme(Uniwind.currentTheme)
14
14
  setHasAdaptiveThemes(Uniwind.hasAdaptiveThemes)
package/src/vite/vite.ts CHANGED
@@ -38,6 +38,16 @@ export const uniwind = ({
38
38
 
39
39
  return {
40
40
  name: 'uniwind',
41
+ enforce: 'pre',
42
+ resolveId: (source, importer) => {
43
+ const normalizedSource = normalizePath(source)
44
+ const isTarget = source === './createOrderedCSSStyleSheet'
45
+ || normalizedSource.endsWith('react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js')
46
+
47
+ if (isTarget && importer !== undefined && normalizePath(importer).includes('react-native-web/dist/exports/StyleSheet')) {
48
+ return styleSheetPath
49
+ }
50
+ },
41
51
  config: () => ({
42
52
  css: {
43
53
  transformer: 'lightningcss',