@shopify/cli-hydrogen 7.1.1 → 7.1.2
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.
- package/dist/generator-templates/assets/vite/package.json +1 -1
- package/dist/generator-templates/starter/CHANGELOG.md +15 -0
- package/dist/generator-templates/starter/app/components/Search.tsx +12 -7
- package/dist/generator-templates/starter/app/routes/api.predictive-search.tsx +8 -15
- package/dist/generator-templates/starter/package.json +3 -3
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# skeleton
|
|
2
2
|
|
|
3
|
+
## 1.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Improve performance of predictive search: ([#1823](https://github.com/Shopify/hydrogen/pull/1823)) by [@frandiox](https://github.com/frandiox)
|
|
8
|
+
|
|
9
|
+
- Change the request to be GET instead of POST to avoid Remix route revalidations.
|
|
10
|
+
- Add Cache-Control headers to the response to get quicker results when typing.
|
|
11
|
+
|
|
12
|
+
Aside from that, it now shows a loading state when fetching the results instead of "No results found.".
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [[`351b3c1b`](https://github.com/Shopify/hydrogen/commit/351b3c1b7768870793ff072ba91426107ba0180c), [`5060cf57`](https://github.com/Shopify/hydrogen/commit/5060cf57f69d8391b425b54acaa487af1f7405ae), [`2888014e`](https://github.com/Shopify/hydrogen/commit/2888014e54fab72c150e9eca55df3c6dd789503e)]:
|
|
15
|
+
- @shopify/hydrogen@2024.1.4
|
|
16
|
+
- @shopify/cli-hydrogen@7.1.2
|
|
17
|
+
|
|
3
18
|
## 1.0.5
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -263,20 +263,18 @@ type ChildrenRenderProps = {
|
|
|
263
263
|
|
|
264
264
|
type SearchFromProps = {
|
|
265
265
|
action?: FormProps['action'];
|
|
266
|
-
method?: FormProps['method'];
|
|
267
266
|
className?: string;
|
|
268
267
|
children: (passedProps: ChildrenRenderProps) => React.ReactNode;
|
|
269
268
|
[key: string]: unknown;
|
|
270
269
|
};
|
|
271
270
|
|
|
272
271
|
/**
|
|
273
|
-
* Search form component that
|
|
272
|
+
* Search form component that sends search requests to the `/search` route
|
|
274
273
|
**/
|
|
275
274
|
export function PredictiveSearchForm({
|
|
276
275
|
action,
|
|
277
276
|
children,
|
|
278
277
|
className = 'predictive-search-form',
|
|
279
|
-
method = 'POST',
|
|
280
278
|
...props
|
|
281
279
|
}: SearchFromProps) {
|
|
282
280
|
const params = useParams();
|
|
@@ -287,13 +285,14 @@ export function PredictiveSearchForm({
|
|
|
287
285
|
|
|
288
286
|
function fetchResults(event: React.ChangeEvent<HTMLInputElement>) {
|
|
289
287
|
const searchAction = action ?? '/api/predictive-search';
|
|
288
|
+
const newSearchTerm = event.target.value || '';
|
|
290
289
|
const localizedAction = params.locale
|
|
291
290
|
? `/${params.locale}${searchAction}`
|
|
292
291
|
: searchAction;
|
|
293
|
-
|
|
292
|
+
|
|
294
293
|
fetcher.submit(
|
|
295
294
|
{q: newSearchTerm, limit: '6'},
|
|
296
|
-
{method, action: localizedAction},
|
|
295
|
+
{method: 'GET', action: localizedAction},
|
|
297
296
|
);
|
|
298
297
|
}
|
|
299
298
|
|
|
@@ -322,7 +321,7 @@ export function PredictiveSearchForm({
|
|
|
322
321
|
}
|
|
323
322
|
|
|
324
323
|
export function PredictiveSearchResults() {
|
|
325
|
-
const {results, totalResults, searchInputRef, searchTerm} =
|
|
324
|
+
const {results, totalResults, searchInputRef, searchTerm, state} =
|
|
326
325
|
usePredictiveSearch();
|
|
327
326
|
|
|
328
327
|
function goToSearchResult(event: React.MouseEvent<HTMLAnchorElement>) {
|
|
@@ -333,9 +332,14 @@ export function PredictiveSearchResults() {
|
|
|
333
332
|
window.location.href = event.currentTarget.href;
|
|
334
333
|
}
|
|
335
334
|
|
|
335
|
+
if (state === 'loading') {
|
|
336
|
+
return <div>Loading...</div>;
|
|
337
|
+
}
|
|
338
|
+
|
|
336
339
|
if (!totalResults) {
|
|
337
340
|
return <NoPredictiveSearchResults searchTerm={searchTerm} />;
|
|
338
341
|
}
|
|
342
|
+
|
|
339
343
|
return (
|
|
340
344
|
<div className="predictive-search-results">
|
|
341
345
|
<div>
|
|
@@ -452,6 +456,7 @@ function SearchResultItem({goToSearchResult, item}: SearchResultItemProps) {
|
|
|
452
456
|
type UseSearchReturn = NormalizedPredictiveSearch & {
|
|
453
457
|
searchInputRef: React.MutableRefObject<HTMLInputElement | null>;
|
|
454
458
|
searchTerm: React.MutableRefObject<string>;
|
|
459
|
+
state: ReturnType<typeof useFetcher>['state'];
|
|
455
460
|
};
|
|
456
461
|
|
|
457
462
|
function usePredictiveSearch(): UseSearchReturn {
|
|
@@ -474,7 +479,7 @@ function usePredictiveSearch(): UseSearchReturn {
|
|
|
474
479
|
searchInputRef.current = document.querySelector('input[type="search"]');
|
|
475
480
|
}, []);
|
|
476
481
|
|
|
477
|
-
return {...search, searchInputRef, searchTerm};
|
|
482
|
+
return {...search, searchInputRef, searchTerm, state: searchFetcher.state};
|
|
478
483
|
}
|
|
479
484
|
|
|
480
485
|
/**
|
|
@@ -34,18 +34,16 @@ const DEFAULT_SEARCH_TYPES: PredictiveSearchTypes[] = [
|
|
|
34
34
|
* Fetches the search results from the predictive search API
|
|
35
35
|
* requested by the SearchForm component
|
|
36
36
|
*/
|
|
37
|
-
export async function
|
|
38
|
-
if (request.method !== 'POST') {
|
|
39
|
-
throw new Error('Invalid request method');
|
|
40
|
-
}
|
|
41
|
-
|
|
37
|
+
export async function loader({request, params, context}: LoaderFunctionArgs) {
|
|
42
38
|
const search = await fetchPredictiveSearchResults({
|
|
43
39
|
params,
|
|
44
40
|
request,
|
|
45
41
|
context,
|
|
46
42
|
});
|
|
47
43
|
|
|
48
|
-
return json(search
|
|
44
|
+
return json(search, {
|
|
45
|
+
headers: {'Cache-Control': `max-age=${search.searchTerm ? 60 : 3600}`},
|
|
46
|
+
});
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
async function fetchPredictiveSearchResults({
|
|
@@ -55,15 +53,10 @@ async function fetchPredictiveSearchResults({
|
|
|
55
53
|
}: Pick<LoaderFunctionArgs, 'params' | 'context' | 'request'>) {
|
|
56
54
|
const url = new URL(request.url);
|
|
57
55
|
const searchParams = new URLSearchParams(url.search);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const searchTerm = String(body?.get('q') || searchParams.get('q') || '');
|
|
63
|
-
const limit = Number(body?.get('limit') || searchParams.get('limit') || 10);
|
|
64
|
-
const rawTypes = String(
|
|
65
|
-
body?.get('type') || searchParams.get('type') || 'ANY',
|
|
66
|
-
);
|
|
56
|
+
const searchTerm = searchParams.get('q') || '';
|
|
57
|
+
const limit = Number(searchParams.get('limit') || 10);
|
|
58
|
+
const rawTypes = String(searchParams.get('type') || 'ANY');
|
|
59
|
+
|
|
67
60
|
const searchTypes =
|
|
68
61
|
rawTypes === 'ANY'
|
|
69
62
|
? DEFAULT_SEARCH_TYPES
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "skeleton",
|
|
3
3
|
"private": true,
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.6",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "shopify hydrogen build",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"@remix-run/react": "^2.8.0",
|
|
18
18
|
"@remix-run/server-runtime": "^2.8.0",
|
|
19
19
|
"@shopify/cli": "3.56.3",
|
|
20
|
-
"@shopify/cli-hydrogen": "^7.1.
|
|
21
|
-
"@shopify/hydrogen": "~2024.1.
|
|
20
|
+
"@shopify/cli-hydrogen": "^7.1.2",
|
|
21
|
+
"@shopify/hydrogen": "~2024.1.4",
|
|
22
22
|
"@shopify/remix-oxygen": "^2.0.3",
|
|
23
23
|
"graphql": "^16.6.0",
|
|
24
24
|
"graphql-tag": "^2.12.6",
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public",
|
|
5
5
|
"@shopify:registry": "https://registry.npmjs.org"
|
|
6
6
|
},
|
|
7
|
-
"version": "7.1.
|
|
7
|
+
"version": "7.1.2",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"flame-chart-js": "2.3.2",
|
|
32
32
|
"get-port": "^7.0.0",
|
|
33
33
|
"type-fest": "^4.5.0",
|
|
34
|
-
"vite": "
|
|
34
|
+
"vite": "~5.1.0",
|
|
35
35
|
"vitest": "^1.0.4"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@remix-run/dev": "^2.1.0",
|
|
68
|
-
"vite": "
|
|
68
|
+
"vite": "~5.1.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependenciesMeta": {
|
|
71
71
|
"@remix-run/dev": {
|