Skip to content

Commit 0f1fc1a

Browse files
authored
Merge pull request #241 from pluginpal/fix/prevent-unnecessary-network-requests
Prevent unnecessary network requests
2 parents 0b4d82c + bb50837 commit 0f1fc1a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

.changeset/eleven-papers-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"strapi-plugin-webtools": patch
3+
---
4+
5+
fix: prevent unnecessary network requests for content types that have Webtools disabled

packages/core/admin/components/EditView/index.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const EditView = () => {
1818

1919
const urlParams = new URLSearchParams(window.location.search);
2020
const locale = urlParams.get('plugins[i18n][locale]');
21-
const aliases = useQuery(`aliases-${model}-${id}-${locale}`, async () => get<UrlAliasEntity[]>(`/webtools/url-alias/findFrom?model=${model}&documentId=${id}&locale=${locale}`));
21+
const aliases = useQuery(`aliases-${model}-${id}-${locale}`, async () => get<UrlAliasEntity[]>(`/webtools/url-alias/findFrom?model=${model}&documentId=${id}&locale=${locale}`), { enabled: false });
2222

2323
/**
2424
* Ideally the url_alias field would be hidden, but doing so will cause an issue.
@@ -44,12 +44,20 @@ const EditView = () => {
4444
}
4545
}, []);
4646

47-
if (aliases.isLoading) return null;
48-
if (aliases.error) return null;
49-
5047
// @ts-expect-error
48+
// Early return if the content type is not enabled.
5149
if (!isContentTypeEnabled(contentType)) return null;
5250

51+
// Fetch the aliases
52+
if (aliases.isIdle) {
53+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
54+
aliases.refetch();
55+
}
56+
57+
// Early return for loading and error states.
58+
if (aliases.isLoading) return null;
59+
if (aliases.error) return null;
60+
5361
return (
5462
<Page.Protect permissions={pluginPermissions['edit-view.sidebar']}>
5563
<EditForm />

0 commit comments

Comments
 (0)