Fix marketplace tab reset state (#40601)

This commit is contained in:
berislav grgičak 2023-10-06 07:13:01 +02:00 committed by GitHub
commit 5c7698a9ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -26,6 +26,7 @@ export default function Content(): JSX.Element {
// Get the content for this screen
useEffect( () => {
const abortController = new AbortController();
if ( [ '', 'discover' ].includes( selectedTab ) ) {
return;
}
@ -62,7 +63,7 @@ export default function Content(): JSX.Element {
params.toString();
// Fetch data from WCCOM API
fetch( wccomSearchEndpoint )
fetch( wccomSearchEndpoint, { signal: abortController.signal } )
.then( ( response ) => response.json() )
.then( ( response ) => {
/**
@ -96,6 +97,9 @@ export default function Content(): JSX.Element {
.finally( () => {
setIsLoading( false );
} );
return () => {
abortController.abort();
};
}, [ query.term, query.category, selectedTab, setIsLoading ] );
const renderContent = (): JSX.Element => {

View File

@ -60,14 +60,12 @@ const tabs: Tabs = {
};
const setUrlTabParam = ( tabKey: string ) => {
if ( tabKey === DEFAULT_TAB_KEY ) {
navigateTo( {
url: getNewPath( {}, MARKETPLACE_PATH, {} ),
} );
return;
}
navigateTo( {
url: getNewPath( { tab: tabKey } ),
url: getNewPath(
{ tab: tabKey === DEFAULT_TAB_KEY ? undefined : tabKey },
MARKETPLACE_PATH,
{}
),
} );
};

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Comment: Fix content rendering issues with changing Marketplace tabs.