@rootnative/core 0.0.0-alpha.15 → 0.0.0-alpha.17
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.d.mts +22 -0
- package/dist/index.mjs +14 -2
- package/llms.txt +11 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -307,6 +307,28 @@ declare const breakpoints: {
|
|
|
307
307
|
* Returns the current Material Design 3 window size class based on viewport width.
|
|
308
308
|
* Reactively updates when the window is resized.
|
|
309
309
|
*
|
|
310
|
+
* **Hydration-safe by construction.** A static export renders on a server with
|
|
311
|
+
* no DOM, where react-native-web's `Dimensions` is hard-wired to `width: 0`,
|
|
312
|
+
* so every breakpoint resolves to `compact` and that is what ships in the
|
|
313
|
+
* HTML. On the client `Dimensions` reports the real width immediately, so
|
|
314
|
+
* without care the first client render disagrees with the markup it is
|
|
315
|
+
* hydrating — and **React does not repair that**. Measured against React
|
|
316
|
+
* 19.2.3: a `className` / `style` mismatch is adopted from the server DOM,
|
|
317
|
+
* left on screen, and reported through *zero* recoverable errors. A tablet
|
|
318
|
+
* gets the phone layout, permanently, with no console signal.
|
|
319
|
+
*
|
|
320
|
+
* So this hook reports `compact` for as long as the client is hydrating,
|
|
321
|
+
* matching the markup exactly, and switches to the measured breakpoint on the
|
|
322
|
+
* re-render React schedules once hydration finishes. The correction is an
|
|
323
|
+
* ordinary update, which *does* patch the DOM.
|
|
324
|
+
*
|
|
325
|
+
* **It costs nothing where there is no hydration.** On native, and on a
|
|
326
|
+
* single-page web build, `getServerSnapshot` is never called, so the measured
|
|
327
|
+
* breakpoint is returned from the first render with no extra pass. Consumers
|
|
328
|
+
* need no `useHydrated` gate of their own, and neither does `Grid`, which
|
|
329
|
+
* resolves a breakpoint map internally and gives a consumer nowhere to put
|
|
330
|
+
* one.
|
|
331
|
+
*
|
|
310
332
|
* @example
|
|
311
333
|
* const breakpoint = useBreakpoint()
|
|
312
334
|
* const columns = breakpoint === 'compact' ? 2 : 4
|
package/dist/index.mjs
CHANGED
|
@@ -254,7 +254,9 @@ function ThemeProvider({
|
|
|
254
254
|
() => !storage || isControlled || !pair
|
|
255
255
|
);
|
|
256
256
|
const storageRef = React4.useRef(storage);
|
|
257
|
-
|
|
257
|
+
React4.useEffect(() => {
|
|
258
|
+
storageRef.current = storage;
|
|
259
|
+
});
|
|
258
260
|
const shouldLoad = Boolean(storage) && !isControlled && Boolean(pair);
|
|
259
261
|
React4.useEffect(() => {
|
|
260
262
|
if (!shouldLoad) {
|
|
@@ -340,6 +342,7 @@ function useIconResolver() {
|
|
|
340
342
|
}
|
|
341
343
|
|
|
342
344
|
// src/responsive/useBreakpoint.ts
|
|
345
|
+
import { useSyncExternalStore } from "react";
|
|
343
346
|
import { useWindowDimensions } from "react-native";
|
|
344
347
|
var breakpoints = {
|
|
345
348
|
compact: 0,
|
|
@@ -355,9 +358,18 @@ function getBreakpoint(width) {
|
|
|
355
358
|
if (width >= breakpoints.medium) return "medium";
|
|
356
359
|
return "compact";
|
|
357
360
|
}
|
|
361
|
+
var subscribeToNothing = () => () => {
|
|
362
|
+
};
|
|
363
|
+
var notHydrating = () => false;
|
|
364
|
+
var isHydratingOnServer = () => true;
|
|
358
365
|
function useBreakpoint() {
|
|
359
366
|
const { width } = useWindowDimensions();
|
|
360
|
-
|
|
367
|
+
const hydrating = useSyncExternalStore(
|
|
368
|
+
subscribeToNothing,
|
|
369
|
+
notHydrating,
|
|
370
|
+
isHydratingOnServer
|
|
371
|
+
);
|
|
372
|
+
return getBreakpoint(hydrating ? 0 : width);
|
|
361
373
|
}
|
|
362
374
|
|
|
363
375
|
// src/responsive/useBreakpointValue.ts
|
package/llms.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @rootnative/core — Theme System for React Native
|
|
2
2
|
|
|
3
|
-
> Version: 0.0.0-alpha.
|
|
3
|
+
> Version: 0.0.0-alpha.17
|
|
4
4
|
> Peer deps: react >=19.2.3 <20.0.0, react-native >=0.83.0 <0.87.0, @rootnative/inertia >=0.0.11 <0.1.0 (required — every animation runs on it)
|
|
5
5
|
> createMaterialTheme needs no extra install — its color engine (@material/material-color-utilities) is bundled behind the create-theme subpath
|
|
6
6
|
|
|
@@ -323,3 +323,13 @@ const columns = useBreakpointValue({ compact: 1, medium: 2, expanded: 4 })
|
|
|
323
323
|
|
|
324
324
|
Type: `useBreakpointValue<T>(values: Partial<Record<Breakpoint, T>> & Record<'compact', T>): T`
|
|
325
325
|
|
|
326
|
+
### Breakpoints and static export (web)
|
|
327
|
+
|
|
328
|
+
Both hooks are hydration-safe, so **no `useHydrated` gate is needed at the call site**.
|
|
329
|
+
|
|
330
|
+
A static export (`web.output: 'static'`) renders on a server with no DOM, where react-native-web's `Dimensions` is fixed at `width: 0` — so every breakpoint resolves to `compact` and that is what ships in the HTML. React 19 does **not** repair a `className`/`style` mismatch during hydration: it adopts the server DOM, keeps it, and fires no recoverable error, so a tablet would silently keep the phone layout.
|
|
331
|
+
|
|
332
|
+
`useBreakpoint` therefore reports `compact` for as long as the client is hydrating, matching that markup, and switches to the measured breakpoint on the re-render React schedules once hydration finishes. On native and on a single-page web build there is no hydration, so the measured value is returned from the first render at no cost.
|
|
333
|
+
|
|
334
|
+
The practical consequence: a breakpoint-dependent layout **starts compact and widens a frame later** on a static export. That is unavoidable — the server cannot know the viewport — so design the compact variant to be the honest first paint. `Grid` inherits all of this, which matters because it resolves a `columns` map internally and leaves a consumer nowhere to put a gate of their own.
|
|
335
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rootnative/core",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.17",
|
|
4
4
|
"description": "Design-system agnostic theme engine for RootNative UI — a React Native component library. Ships with Material Design 3 out of the box.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@material/material-color-utilities": "^0.4.0",
|
|
62
62
|
"@react-native/babel-preset": "^0.86.3",
|
|
63
63
|
"@react-native/jest-preset": "^0.86.3",
|
|
64
|
-
"@rootnative/inertia": "0.0.
|
|
64
|
+
"@rootnative/inertia": "0.0.13",
|
|
65
65
|
"@testing-library/react-native": "^13.3.3",
|
|
66
66
|
"@types/jest": "^29.5.14",
|
|
67
67
|
"@types/react": "^19.0.0",
|