@tapcart/mobile-components 0.11.3 → 0.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"use-infinite-scroll.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-infinite-scroll.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAmB,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAE5D,UAAU,QAAQ;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,GAAG,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;CACxC;AAED,UAAU,sBAAsB;IAE9B,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAGxC,WAAW,CAAC,EAAE,QAAQ,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAGpC,SAAS,CAAC,EAAE,UAAU,GAAG,YAAY,CAAA;IACrC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAChD,YAAY,CAAC,EAAE,CACb,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,GAAG,GAAG,IAAI,EAC5B,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,GAAG,CAAA;CACT;AAED,UAAU,uBAAuB;IAC/B,IAAI,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAA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AAE,GAAG,CAAC,CAAA;IAGpC,SAAS,CAAC,EAAE,UAAU,GAAG,YAAY,CAAA;IACrC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAChD,YAAY,CAAC,EAAE,CACb,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,GAAG,GAAG,IAAI,EAC5B,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,GAAG,CAAA;CACT;AAED,UAAU,uBAAuB;IAC/B,IAAI,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAA;IAC5B,KAAK,EAAE,GAAG,CAAA;IACV,oBAAoB,EAAE,OAAO,CAAA;IAC7B,aAAa,EAAE,OAAO,GAAG,SAAS,CAAA;IAClC,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,OAAO,CAAA;IACtB,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAA;IAChD,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,oBAAoB,EAAE,GAAG,EAAE,CAAA;IAC3B,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,EAAE,OAAO,CAAA;CACtB;AAED,eAAO,MAAM,sCAAsC,iBACnC,uBAAuB,OAsBtC,CAAA;AAED,QAAA,MAAM,YAAY,WAAY,MAAM,WAGnC,CAAA;AAED,QAAA,MAAM,iBAAiB,kJAepB,sBAAsB,KAAG,uBAuR3B,CAAA;AAED,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAA"}
@@ -52,6 +52,12 @@ customFetcher, customGetKey, }) => {
52
52
  var _a, _b, _c, _d, _e;
53
53
  const searchParams = useSearchParams();
54
54
  const productCount = useRef(0);
55
+ const isFirstRender = useRef(true);
56
+ const prevParamsRef = useRef({
57
+ collectionId: null,
58
+ collectionHandle: null,
59
+ searchQuery: null,
60
+ });
55
61
  const { ref, inView } = useInView({
56
62
  rootMargin: direction === "vertical" ? "600px" : "0px 420px 0px 0px",
57
63
  threshold: threshold,
@@ -60,26 +66,19 @@ customFetcher, customGetKey, }) => {
60
66
  const usingSearchClient = Boolean(searchClient);
61
67
  const { handle, id } = (searchClient === null || searchClient === void 0 ? void 0 : searchClient.getCollection()) || {};
62
68
  const query = searchClient === null || searchClient === void 0 ? void 0 : searchClient.getQuery();
69
+ // Extract current critical params
70
+ const currentCollectionId = (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionId")) || id || (queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionId);
71
+ const currentCollectionHandle = (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionHandle")) ||
72
+ handle ||
73
+ (queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionHandle);
74
+ const currentSearchQuery = (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("searchQuery")) || query || (queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.searchQuery);
63
75
  // Determine whether we should skip fetching for search client approach
64
76
  const hasCollection = useMemo(() => {
65
- return Boolean((searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionId")) ||
66
- (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionHandle")) ||
67
- handle ||
68
- id ||
69
- (queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionId) ||
70
- (queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionHandle));
71
- }, [
72
- searchParams,
73
- handle,
74
- id,
75
- queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionId,
76
- queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionHandle,
77
- ]);
77
+ return Boolean(currentCollectionId || currentCollectionHandle);
78
+ }, [currentCollectionId, currentCollectionHandle]);
78
79
  const hasQuery = useMemo(() => {
79
- return (Boolean(searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("searchQuery")) ||
80
- query ||
81
- (queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.searchQuery));
82
- }, [searchParams, query, queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.searchQuery]);
80
+ return Boolean(currentSearchQuery);
81
+ }, [currentSearchQuery]);
83
82
  const shouldSkipFetch = !hasCollection && !hasQuery;
84
83
  // Search client approach - getKey and fetcher
85
84
  const searchClientGetKey = useMemo(() => customGetKey || (searchClient === null || searchClient === void 0 ? void 0 : searchClient.getKey), [customGetKey, searchClient === null || searchClient === void 0 ? void 0 : searchClient.getKey]);
@@ -113,21 +112,25 @@ customFetcher, customGetKey, }) => {
113
112
  productCount.current += (_g = (_f = data === null || data === void 0 ? void 0 : data.products) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0;
114
113
  return data;
115
114
  });
116
- // Determine which approach to use
115
+ // Return null from getKey to conditionally skip fetching
116
+ // When getKey returns null, SWR won't fetch and won't cache anything
117
+ // https://swr.vercel.app/docs/conditional-fetching
117
118
  const getKey = usingSearchClient
118
119
  ? (pageIndex, previousPageData) => {
120
+ if (shouldSkipFetch)
121
+ return null;
119
122
  if (!searchClientGetKey)
120
123
  return null;
121
124
  return searchClientGetKey(pageIndex, previousPageData);
122
125
  }
123
126
  : (pageIndex, previousPageData) => {
127
+ if (shouldSkipFetch)
128
+ return null;
124
129
  return (customGetKey || apiGetKey)(pageIndex, previousPageData, queryVariables !== null && queryVariables !== void 0 ? queryVariables : {});
125
130
  };
126
131
  const fetcher = usingSearchClient
127
132
  ? (...args) => __awaiter(void 0, void 0, void 0, function* () {
128
133
  var _h, _j;
129
- if (shouldSkipFetch)
130
- return null;
131
134
  if (!searchClientFetcher)
132
135
  return null;
133
136
  const result = yield searchClientFetcher(...args);
@@ -135,8 +138,6 @@ customFetcher, customGetKey, }) => {
135
138
  return result;
136
139
  })
137
140
  : (...args) => __awaiter(void 0, void 0, void 0, function* () {
138
- if (shouldSkipFetch)
139
- return null;
140
141
  const effectiveFetcher = customFetcher || apiFetcher;
141
142
  return effectiveFetcher(...args);
142
143
  });
@@ -144,6 +145,28 @@ customFetcher, customGetKey, }) => {
144
145
  revalidateFirstPage: false,
145
146
  initialSize: 1,
146
147
  });
148
+ // Detect when params change and force cache invalidation
149
+ useEffect(() => {
150
+ const prevParams = prevParamsRef.current;
151
+ const paramsChanged = prevParams.collectionId !== currentCollectionId ||
152
+ prevParams.collectionHandle !== currentCollectionHandle ||
153
+ prevParams.searchQuery !== currentSearchQuery;
154
+ if (paramsChanged) {
155
+ const hasValidCurrentParams = Boolean(currentCollectionId || currentCollectionHandle || currentSearchQuery);
156
+ // Update the ref
157
+ prevParamsRef.current = {
158
+ collectionId: currentCollectionId,
159
+ collectionHandle: currentCollectionHandle,
160
+ searchQuery: currentSearchQuery,
161
+ };
162
+ // Skip reset on first render, but force it for any subsequent transitions to valid params
163
+ if (!isFirstRender.current && hasValidCurrentParams) {
164
+ productCount.current = 0;
165
+ mutate(undefined, { revalidate: true });
166
+ }
167
+ }
168
+ isFirstRender.current = false;
169
+ }, [currentCollectionId, currentCollectionHandle, currentSearchQuery, mutate]);
147
170
  const isLoadingInitialData = !data && !error;
148
171
  const isLoadingMore = isLoadingInitialData ||
149
172
  (size > 0 && data && typeof data[size - 1] === "undefined");
@@ -204,7 +227,8 @@ customFetcher, customGetKey, }) => {
204
227
  return [];
205
228
  return data.map((page) => { var _a; return (_a = page === null || page === void 0 ? void 0 : page.integrationResponse) !== null && _a !== void 0 ? _a : null; });
206
229
  }, [data, usingSearchClient]);
207
- // Elegant conditional overrides when skipping
230
+ // Safety fallback: When shouldSkipFetch is true, getKey returns null so SWR won't fetch
231
+ // This applySkip is a defensive fallback to ensure consistent return values
208
232
  const applySkip = useCallback((value, override) => (shouldSkipFetch ? override : value), [shouldSkipFetch]);
209
233
  return useMemo(() => ({
210
234
  data,
package/dist/styles.css CHANGED
@@ -1009,6 +1009,9 @@ video {
1009
1009
  .h-20 {
1010
1010
  height: 5rem;
1011
1011
  }
1012
+ .h-24 {
1013
+ height: 6rem;
1014
+ }
1012
1015
  .h-4 {
1013
1016
  height: 1rem;
1014
1017
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapcart/mobile-components",
3
- "version": "0.11.3",
3
+ "version": "0.11.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/styles.css",