Skip to content

Commit 176fb6d

Browse files
authored
fix(webapp): call hooks directly and unconditionally (#4715)
## Summary Calls dashboard hooks directly instead of passing them as ordinary callback values, and subscribes to optional Ariakit stores through an unconditional hook. This keeps hook ordering stable while preserving the existing behavior when a provider is absent.
1 parent 6dfc54b commit 176fb6d

5 files changed

Lines changed: 11 additions & 8 deletions

File tree

apps/webapp/app/components/primitives/Select.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Ariakit from "@ariakit/react";
22
import { type SelectProps as AriaSelectProps } from "@ariakit/react";
33
import { SelectValue } from "@ariakit/react-core/select/select-value";
4+
import { useStoreState } from "@ariakit/react-core/utils/store";
45
import { Link } from "@remix-run/react";
56
import * as React from "react";
67
import { Fragment, useMemo, useState } from "react";
@@ -484,7 +485,7 @@ export function SelectItem({
484485
const render = combobox ? <Ariakit.ComboboxItem render={props.render} /> : props.render;
485486
const ref = React.useRef<HTMLDivElement>(null);
486487
const select = Ariakit.useSelectContext();
487-
const selectValue = select?.useState("value");
488+
const selectValue = useStoreState(select, "value");
488489

489490
const isChecked = React.useMemo(() => {
490491
if (!props.value || selectValue == null) return false;
@@ -692,8 +693,8 @@ export function ComboBox({
692693
...props
693694
}: ComboBoxProps) {
694695
const combobox = Ariakit.useComboboxContext();
695-
const open = combobox?.useState("open");
696-
const input = combobox?.useState("baseElement");
696+
const open = useStoreState(combobox, "open");
697+
const input = useStoreState(combobox, "baseElement");
697698

698699
React.useEffect(() => {
699700
if (!open || !input) return;

apps/webapp/app/hooks/useChanged.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import { useEffect, useRef } from "react";
22

33
/** Call a function when the id of the item changes */
44
export function useChanged<T extends { id: string }>(
5-
getItem: () => T | undefined,
5+
item: T | undefined,
66
action: (item: T | undefined) => void,
77
sendInitialUndefined = true
88
) {
99
const previousItemId = useRef<string | undefined>();
1010
const isInitialRender = useRef(true);
1111
const actionRef = useRef(action);
1212
const itemRef = useRef<T | undefined>();
13-
const item = getItem();
1413
const itemId = item?.id;
1514

1615
actionRef.current = action;

apps/webapp/app/hooks/useOrganizations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export function useOrganization(matches?: UIMatch[]) {
4343
}
4444

4545
export const useOrganizationChanged = (action: (org: MatchedOrganization | undefined) => void) => {
46-
useChanged(useOptionalOrganization, action);
46+
const organization = useOptionalOrganization();
47+
useChanged(organization, action);
4748
};
4849

4950
export function useIsImpersonating(matches?: UIMatch[]) {

apps/webapp/app/hooks/useProject.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ export function useProject(matches?: UIMatch[]) {
2424
}
2525

2626
export const useProjectChanged = (action: (org: MatchedProject | undefined) => void) => {
27-
useChanged(useOptionalProject, action);
27+
const project = useOptionalProject();
28+
useChanged(project, action);
2829
};

apps/webapp/app/hooks/useUser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export function useUser(matches?: UIMatch[]): User {
2727
}
2828

2929
export function useUserChanged(callback: (user: User | undefined) => void) {
30-
useChanged(useOptionalUser, callback);
30+
const user = useOptionalUser();
31+
useChanged(user, callback);
3132
}
3233

3334
/**

0 commit comments

Comments
 (0)