Merge pull request #14239 from strapi/fix/cm-localepicker

CM: Fix i18n LocalePicker component
This commit is contained in:
Gustav Hansen 2022-08-30 09:33:20 +02:00 committed by GitHub
commit 378ab81aee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,13 +49,23 @@ const LocalePicker = () => {
return;
}
dispatch({ type: 'ContentManager/RBACManager/RESET_PERMISSIONS' });
setSelected(code);
setQuery({
page: 1,
plugins: { ...query.plugins, i18n: { locale: code } },
/**
* if the selected value is set at the same time as the dispatcher
* is run, react might not have enough time to re-render the Select
* component, which leads to the `source` ref, which is passed to
* Popout, not being defined.
*
* By pushing the dispatcher to the end of the current execution
* context, we can guarantee the rendering can finish before.
*/
setTimeout(() => {
dispatch({ type: 'ContentManager/RBACManager/RESET_PERMISSIONS' });
setQuery({
page: 1,
plugins: { ...query.plugins, i18n: { locale: code } },
});
});
};