Skip to content

fix(core): recompute useMenu defaultOpenKeys when the active resource changes - #7684

Open
shreyanks-1 wants to merge 2 commits into
refinedev:mainfrom
shreyanks-1:fix/use-menu-default-open-keys
Open

shreyanks-1 wants to merge 2 commits into
refinedev:mainfrom
shreyanks-1:fix/use-menu-default-open-keys

Conversation

@shreyanks-1

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

useMenu's defaultOpenKeys is memoized with an empty dependency array, even though it reads resource and resources from useResourceParams(). In an app where the sidebar persists across navigation (no remount), navigating between resources does not recompute defaultOpenKeys — it stays stuck at whichever resource was active on the first render, while selectedKey (computed the same way, a few lines above) correctly updates.

What is the new behavior?

defaultOpenKeys's useMemo now depends on [resource, resources], so it recomputes whenever the active resource changes. Added a regression test that renders useMenu with a dynamic router mock, navigates from one resource to a sibling resource without unmounting, and asserts defaultOpenKeys reflects the new resource.

fixes #7683

Notes for reviewers

This exact one-line fix was previously proposed in #7543, which received no reviews or comments and was closed without being merged. This PR carries the same fix plus a from-scratch regression test that explicitly exercises a route change without unmounting — the scenario the empty dependency array breaks, and which wasn't covered by any existing test in useMenu.spec.tsx.

… changes

`defaultOpenKeys` was memoized with an empty dependency array even
though it reads `resource` and `resources`, both of which come from
the current route. In a persistent sidebar (no remount on
navigation), the open keys stayed stuck at whatever resource was
active on first render.

Added `resource` and `resources` to the dependency array, plus a
regression test that navigates between two sibling resources without
unmounting and asserts the open keys follow.
@changeset-bot

changeset-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 03525e8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@refinedev/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]

1 participant