Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move inherit reset to a useEffect
  • Loading branch information
mikachan committed Sep 18, 2024
commit 52aaf5a839e650e19c4a9e1a42640583c554a988
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ export default function QueryInspectorControls( props ) {
updateQuery.format = [];
}

// We need to reset the `inherit` value if not in a template, as queries
// are not inherited when outside a template (e.g. when in singular content).
if ( ! isTemplate ) {
updateQuery.inherit = false;
}

setQuery( updateQuery );
};
const [ querySearch, setQuerySearch ] = useState( query.search );
Expand Down Expand Up @@ -138,6 +132,14 @@ export default function QueryInspectorControls( props ) {
[ postTypeFromContext ]
);

// We need to reset the `inherit` value if not in a template, as queries
// are not inherited when outside a template (e.g. when in singular content).
useEffect( () => {
if ( ! isTemplate && query.inherit ) {
setQuery( { inherit: false } );
}
}, [ isTemplate, query.inherit, setQuery ] );

const showInheritControl =
isTemplate && isControlAllowed( allowedControls, 'inherit' );
const showPostTypeControl =
Expand Down