-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative fix: set persisted menu id when no menus or missing menu #32313
Alternative fix: set persisted menu id when no menus or missing menu #32313
Conversation
0 is a valid menuID so we had requests going out to `/menus/0` which always 404’d. By using `null` as the default we can reset a selected menu ID and ensure that: 1. No requests go out. 2. We’re clearer that we have no menu set.
Size Change: +67 B (0%) Total Size: 1.03 MB
ℹ️ View Unchanged
|
I tested PR by following instructions, and it works as expected. I can see two 404 requests to What will be the downside if we check menu existence inside the Example code: export const getSelectedMenuId = createRegistrySelector(
( select ) => ( state ) => {
const menuId = state.selectedMenuId ?? null;
const menu = menuId
? select( coreStore ).getEntityRecord(
MENU_KIND,
MENU_POST_TYPE,
menuId
)
: null;
if ( ! menu ) {
return null;
}
return menu.id;
}
); I think PR looks good, and I wasn't able to spot any obvious issues code-wise. |
@Mamaduka I'm not 100% but it just feels like querying for menus within a selector which is just supposed to retrieve the selected menu isn't something I'd expect to happen. I'd decided to be more declarative and actually make it obvious when and where we're querying for menus rather than hiding it in and amongst other APIs. I'd be interested to hear what other folks think though... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good and the improvement makes sense.
Description
Alternative to #32306.
In #31320 we started persisting the
selectedMenuId
to localStorage. Code was in place to reset this ID if the menu was deleted. However, there were no guards against the following conditionsThis PR attempts to address this.
Moreover, it resolves the edge case whereby due to a default of
0
for selectedMenuId, requests were being made to/menus/0
for a menu that could never exist. Usingnull
as the default prevents this.Fixes #32256
How has this been tested?
Manually only - needs e2e and unit tests.
Manual Instructions
Menu 1
andMenu 2
.Menu 2
. Make a note of it's menu ID by checking the state or network requests.Menu 2
.Menu 1
becomes selected in the Navigation Editor./menus/{{MENU_ID_OF_MENU_2}}
in the Network tab./menus/0
in the Network tab.Menu 1
./menus/{{MENU_ID_OF_MENU_1}}
in the Network tab./menus/0
in the Network tab.It should be impossible to arrive at the state observed in #32256.
Screenshots
Screen.Capture.on.2021-05-28.at.12-53-19.mov
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).