@csszyx/dynamic 0.10.9 → 0.10.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.
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '@csszyx/compiler/browser';
|
|
2
|
-
export { a as cleanup, d as dynamic, b as preloadManifest, e as purifySz } from './shared/dynamic.
|
|
2
|
+
export { a as cleanup, d as dynamic, b as preloadManifest, e as purifySz } from './shared/dynamic.BWQj5dWI.mjs';
|
package/dist/react.d.mts
CHANGED
|
@@ -46,6 +46,12 @@ interface UseSzReturn {
|
|
|
46
46
|
*/
|
|
47
47
|
sz: (props: SzObject) => string;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Reset the shared consumer counter and pending timer — test-only. Module
|
|
51
|
+
* state persists across tests in one suite, so suites that simulate
|
|
52
|
+
* mount/unmount cycles must start from a known-empty lifecycle.
|
|
53
|
+
*/
|
|
54
|
+
declare function _resetUseSzLifecycle(): void;
|
|
49
55
|
/**
|
|
50
56
|
* React hook for runtime dynamic styling.
|
|
51
57
|
*
|
|
@@ -82,5 +88,5 @@ interface CsszyxProviderProps {
|
|
|
82
88
|
*/
|
|
83
89
|
declare function CsszyxProvider({ manifest, children }: CsszyxProviderProps): ReactElement;
|
|
84
90
|
|
|
85
|
-
export { CsszyxProvider, sz, useSz };
|
|
91
|
+
export { CsszyxProvider, _resetUseSzLifecycle, sz, useSz };
|
|
86
92
|
export type { UseSzReturn };
|
package/dist/react.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useEffect, createElement, useContext, useCallback } from 'react';
|
|
2
|
-
import { d as dynamic, p as preloadManifest, c as cleanup, r as resetManifest, s as setManifestUrl } from './shared/dynamic.
|
|
2
|
+
import { d as dynamic, p as preloadManifest, c as cleanup, r as resetManifest, s as setManifestUrl } from './shared/dynamic.BWQj5dWI.mjs';
|
|
3
3
|
import '@csszyx/compiler/browser';
|
|
4
4
|
|
|
5
5
|
const CsszyxContext = createContext({
|
|
@@ -7,16 +7,30 @@ const CsszyxContext = createContext({
|
|
|
7
7
|
});
|
|
8
8
|
const sz = dynamic;
|
|
9
9
|
let _cleanupTimer = null;
|
|
10
|
+
let _mountedConsumers = 0;
|
|
11
|
+
function cancelPendingCleanup() {
|
|
12
|
+
if (_cleanupTimer !== null) {
|
|
13
|
+
clearTimeout(_cleanupTimer);
|
|
14
|
+
_cleanupTimer = null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _resetUseSzLifecycle() {
|
|
18
|
+
cancelPendingCleanup();
|
|
19
|
+
_mountedConsumers = 0;
|
|
20
|
+
}
|
|
10
21
|
function useSz() {
|
|
11
22
|
const { manifestUrl } = useContext(CsszyxContext);
|
|
12
23
|
const stableSz = useCallback((props) => dynamic(props), []);
|
|
13
24
|
useEffect(() => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_cleanupTimer = null;
|
|
17
|
-
}
|
|
25
|
+
_mountedConsumers++;
|
|
26
|
+
cancelPendingCleanup();
|
|
18
27
|
preloadManifest(manifestUrl);
|
|
19
28
|
return () => {
|
|
29
|
+
_mountedConsumers--;
|
|
30
|
+
if (_mountedConsumers > 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
cancelPendingCleanup();
|
|
20
34
|
_cleanupTimer = setTimeout(() => {
|
|
21
35
|
cleanup();
|
|
22
36
|
resetManifest();
|
|
@@ -34,4 +48,4 @@ function CsszyxProvider({ manifest, children }) {
|
|
|
34
48
|
return createElement(CsszyxContext.Provider, { value: { manifestUrl: manifest } }, children);
|
|
35
49
|
}
|
|
36
50
|
|
|
37
|
-
export { CsszyxProvider, sz, useSz };
|
|
51
|
+
export { CsszyxProvider, _resetUseSzLifecycle, sz, useSz };
|
|
@@ -1044,6 +1044,8 @@ function supportsConstructableSheets() {
|
|
|
1044
1044
|
let sheets = null;
|
|
1045
1045
|
let fallbackStyle = null;
|
|
1046
1046
|
const injected = /* @__PURE__ */ new Set();
|
|
1047
|
+
const INJECTED_GROWTH_WARN_THRESHOLD = 5e3;
|
|
1048
|
+
let warnedInjectedGrowth = false;
|
|
1047
1049
|
function wrapForTier(cssRule, tier) {
|
|
1048
1050
|
if (tier === "base") {
|
|
1049
1051
|
return cssRule;
|
|
@@ -1097,6 +1099,12 @@ function injectRule(className, cssRule, tier = "base") {
|
|
|
1097
1099
|
return;
|
|
1098
1100
|
}
|
|
1099
1101
|
injected.add(className);
|
|
1102
|
+
if (process.env.NODE_ENV !== "production" && !warnedInjectedGrowth && injected.size >= INJECTED_GROWTH_WARN_THRESHOLD) {
|
|
1103
|
+
warnedInjectedGrowth = true;
|
|
1104
|
+
console.warn(
|
|
1105
|
+
`[csszyx] dynamic() has injected ${INJECTED_GROWTH_WARN_THRESHOLD}+ unique classes this session. Injected CSS rules are never removed, so continuously varying values (e.g. w-[\`\${x}px\`] per animation frame) grow the CSSOM and slow style recalc. Drive continuously changing values through a CSS variable instead.`
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1100
1108
|
if (!cssRule) {
|
|
1101
1109
|
return;
|
|
1102
1110
|
}
|
|
@@ -1133,6 +1141,7 @@ function cleanup$1() {
|
|
|
1133
1141
|
fallbackStyle = null;
|
|
1134
1142
|
}
|
|
1135
1143
|
injected.clear();
|
|
1144
|
+
warnedInjectedGrowth = false;
|
|
1136
1145
|
}
|
|
1137
1146
|
|
|
1138
1147
|
let manifestClasses = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csszyx/dynamic",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.11",
|
|
4
4
|
"description": "Runtime CSS injection engine for @csszyx — injects only CSS not already in the pre-built stylesheet",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"node": ">=22.12.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@csszyx/compiler": "0.10.
|
|
41
|
+
"@csszyx/compiler": "0.10.11"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"react": ">=17.0.0"
|