Skip to content

Commit f04c19e

Browse files
committed
test: hand the router's navigate out through an effect, not a render-time reassignment
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibz6e1jru1WvD8e9e9E
1 parent 1038dac commit f04c19e

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.areaFollowsRoute-28497.test.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,21 @@ const serviceArea: NavigationArea = {
138138
],
139139
};
140140

141-
let navigate: NavigateFunction;
141+
/** The router's navigate, handed out of the tree once it has rendered. */
142+
const router: { navigate: NavigateFunction | null } = { navigate: null };
142143
function NavigateProbe() {
143-
navigate = useNavigate();
144+
const navigate = useNavigate();
145+
React.useEffect(() => {
146+
router.navigate = navigate;
147+
}, [navigate]);
144148
return null;
145149
}
146150

151+
function navigate(path: string) {
152+
if (!router.navigate) throw new Error('the router has not rendered');
153+
void router.navigate(path);
154+
}
155+
147156
function renderAt(path: string) {
148157
metadataState = {
149158
apps: [{ name: 'crm', label: 'CRM', active: true, areas: [salesArea, serviceArea] }],

0 commit comments

Comments
 (0)