Skip to content

Commit d4e86c5

Browse files
fix(plugin-basic-ui): hydration mismatch warning (#436)
1 parent 478b5db commit d4e86c5

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

.changeset/quiet-poems-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stackflow/plugin-basic-ui": patch
3+
---
4+
5+
fix hydration mismatch warning in server-side rendering

extensions/plugin-basic-ui/src/components/AppScreen.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { GlobalVars } from "../basicUIPlugin.css";
77
import { globalVars } from "../basicUIPlugin.css";
88
import {
99
useLazy,
10+
useMounted,
1011
useNullableActivity,
1112
useStyleEffectHide,
1213
useStyleEffectOffset,
@@ -49,6 +50,7 @@ const AppScreen: React.FC<AppScreenProps> = ({
4950
}) => {
5051
const globalOptions = useGlobalOptions();
5152
const activity = useNullableActivity();
53+
const mounted = useMounted();
5254

5355
const { pop } = useActions();
5456

@@ -182,8 +184,10 @@ const AppScreen: React.FC<AppScreenProps> = ({
182184
}),
183185
)}
184186
data-stackflow-component-name="AppScreen"
185-
data-stackflow-activity-id={activity?.id}
186-
data-stackflow-activity-is-active={activity?.isActive}
187+
data-stackflow-activity-id={mounted ? activity?.id : undefined}
188+
data-stackflow-activity-is-active={
189+
mounted ? activity?.isActive : undefined
190+
}
187191
>
188192
{activityEnterStyle !== "slideInLeft" && (
189193
<div className={css.dim} ref={dimRef} />

extensions/plugin-basic-ui/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./useLazy";
22
export * from "./useMaxWidth";
3+
export * from "./useMounted";
34
export * from "./useNullableActivity";
45
export * from "./useStyleEffect";
56
export * from "./useStyleEffectHide";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useEffect, useReducer, useState } from "react";
2+
3+
export function useMounted() {
4+
const [mounted, mount] = useReducer(() => true, false);
5+
6+
useEffect(() => {
7+
mount();
8+
}, []);
9+
10+
return mounted;
11+
}

0 commit comments

Comments
 (0)