Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/eleven-papers-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-plugin-webtools": patch
---

fix: prevent unnecessary network requests for content types that have Webtools disabled
16 changes: 12 additions & 4 deletions packages/core/admin/components/EditView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const EditView = () => {

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

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

if (aliases.isLoading) return null;
if (aliases.error) return null;

// @ts-expect-error
// Early return if the content type is not enabled.
if (!isContentTypeEnabled(contentType)) return null;

// Fetch the aliases
if (aliases.isIdle) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
aliases.refetch();
}

// Early return for loading and error states.
if (aliases.isLoading) return null;
if (aliases.error) return null;

return (
<Page.Protect permissions={pluginPermissions['edit-view.sidebar']}>
<EditForm />
Expand Down
Loading