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 Settings = ( { params } ) => {
const settingsData = window.wcSettings?.admin?.settingsPages; const settingsData = window.wcSettings?.admin?.settingsPages;
const { section } = getQuery();
// Be sure to render Settings slots when the params change. // Be sure to render Settings slots when the params change.
useEffect( () => { useEffect( () => {
possiblyRenderSettingsSlots(); possiblyRenderSettingsSlots();
}, [ params ] ); }, [ params.page, section ] );
// Register the slot fills for the settings page just once. // Register the slot fills for the settings page just once.
useEffect( () => { useEffect( () => {
@ -35,7 +36,6 @@ const Settings = ( { params } ) => {
return <div>Error getting data</div>; return <div>Error getting data</div>;
} }
const { section } = getQuery();
const sections = settingsData[ params.page ]?.sections; const sections = settingsData[ params.page ]?.sections;
const contentData = const contentData =
Array.isArray( sections ) && sections.length === 0 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 { Slot } = createSlotFill( SETTINGS_SLOT_FILL_CONSTANT );
const roots = {};
export const possiblyRenderSettingsSlots = () => { export const possiblyRenderSettingsSlots = () => {
const slots = [ const slots = [
{ {
@ -43,13 +41,8 @@ export const possiblyRenderSettingsSlots = () => {
); );
if ( createRoot ) { if ( createRoot ) {
if ( roots[ slot.id ] ) {
roots[ slot.id ].render( slotFill );
} else {
const root = createRoot( slotDomElement ); const root = createRoot( slotDomElement );
root.render( slotFill ); root.render( slotFill );
roots[ slot.id ] = root;
}
} else { } else {
render( render(
<> <>