Skip to content

Commit

Permalink
fix(plugin-basic-ui): hydration mismatch warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfromundefined committed Jan 15, 2024
1 parent 478b5db commit 4c54106
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions extensions/plugin-basic-ui/src/components/AppScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { GlobalVars } from "../basicUIPlugin.css";
import { globalVars } from "../basicUIPlugin.css";
import {
useLazy,
useMounted,
useNullableActivity,
useStyleEffectHide,
useStyleEffectOffset,
Expand Down Expand Up @@ -49,6 +50,7 @@ const AppScreen: React.FC<AppScreenProps> = ({
}) => {
const globalOptions = useGlobalOptions();
const activity = useNullableActivity();
const mounted = useMounted();

const { pop } = useActions();

Expand Down Expand Up @@ -182,8 +184,10 @@ const AppScreen: React.FC<AppScreenProps> = ({
}),
)}
data-stackflow-component-name="AppScreen"
data-stackflow-activity-id={activity?.id}
data-stackflow-activity-is-active={activity?.isActive}
data-stackflow-activity-id={mounted ? activity?.id : undefined}
data-stackflow-activity-is-active={
mounted ? activity?.isActive : undefined
}
>
{activityEnterStyle !== "slideInLeft" && (
<div className={css.dim} ref={dimRef} />
Expand Down
1 change: 1 addition & 0 deletions extensions/plugin-basic-ui/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./useLazy";
export * from "./useMaxWidth";
export * from "./useMounted";
export * from "./useNullableActivity";
export * from "./useStyleEffect";
export * from "./useStyleEffectHide";
Expand Down
11 changes: 11 additions & 0 deletions extensions/plugin-basic-ui/src/hooks/useMounted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useEffect, useReducer, useState } from "react";

export function useMounted() {
const [mounted, mount] = useReducer(() => true, false);

useEffect(() => {
mount();
}, []);

return mounted;
}

1 comment on commit 4c54106

@vercel
Copy link

@vercel vercel bot commented on 4c54106 Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.