finally get slotFill right

This commit is contained in:
paul sealock 2024-06-04 14:43:59 +12:00
parent 961e4e4a6f
commit 5daf3ec66d
2 changed files with 4 additions and 11 deletions

View File

@ -18,11 +18,12 @@ import './style.scss';
const Settings = ( { params } ) => {
const settingsData = window.wcSettings?.admin?.settingsPages;
const { section } = getQuery();
// Be sure to render Settings slots when the params change.
useEffect( () => {
possiblyRenderSettingsSlots();
}, [ params ] );
}, [ params.page, section ] );
// Register the slot fills for the settings page just once.
useEffect( () => {
@ -35,7 +36,6 @@ const Settings = ( { params } ) => {
return <div>Error getting data</div>;
}
const { section } = getQuery();
const sections = settingsData[ params.page ]?.sections;
const contentData =
Array.isArray( sections ) && sections.length === 0

View File

@ -10,8 +10,6 @@ export const SETTINGS_SLOT_FILL_CONSTANT =
const { Slot } = createSlotFill( SETTINGS_SLOT_FILL_CONSTANT );
const roots = {};
export const possiblyRenderSettingsSlots = () => {
const slots = [
{
@ -43,13 +41,8 @@ export const possiblyRenderSettingsSlots = () => {
);
if ( createRoot ) {
if ( roots[ slot.id ] ) {
roots[ slot.id ].render( slotFill );
} else {
const root = createRoot( slotDomElement );
root.render( slotFill );
roots[ slot.id ] = root;
}
const root = createRoot( slotDomElement );
root.render( slotFill );
} else {
render(
<>