From 56d550e86cfef3373d204e20b4c3faf3e9c16cda Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Sat, 24 Feb 2024 17:23:57 -0800 Subject: [PATCH] Skip loading alt styles on item preview page Ah yeah, if you're not on the wardrobe page (so we don't need the Alt Styles UI), and the outfit's `altStyleId` is null (as is the case for the item preview page), then there's no need to load the alt styles for that species. So before this change, going to `/items/123` would include an XHR request to `/species//alt-styles.json`, which would not be used for anything. After this change, that request is no longer sent. Hooray! --- app/javascript/wardrobe-2020/loaders/alt-styles.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/javascript/wardrobe-2020/loaders/alt-styles.js b/app/javascript/wardrobe-2020/loaders/alt-styles.js index 668745ac..a66f81db 100644 --- a/app/javascript/wardrobe-2020/loaders/alt-styles.js +++ b/app/javascript/wardrobe-2020/loaders/alt-styles.js @@ -12,7 +12,10 @@ export function useAltStylesForSpecies(speciesId, options = {}) { // NOTE: This is actually just a wrapper for `useAltStylesForSpecies`, to share // the same cache key! export function useAltStyle(id, speciesId, options = {}) { - const query = useAltStylesForSpecies(speciesId, options); + const query = useAltStylesForSpecies(speciesId, { + ...options, + enabled: (options.enabled ?? true) && id != null, + }); return { ...query,