@coveo/headless-react 2.1.1-pre.e48646b42a → 2.1.1-pre.ea6085c692

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Subscriber is a function that takes a single argument, which is another function `listener` that returns `void`. The Subscriber function itself returns another function that can be used to unsubscribe the `listener`.
3
+ */
4
+ export type Subscriber = (listener: () => void) => () => void;
5
+ export type SnapshotGetter<T> = () => T;
6
+ /**
7
+ * Alternate for `useSyncExternalStore` which runs into infinite loops when hooks are used in `getSnapshot`
8
+ * https://github.com/facebook/react/issues/24529
9
+ */
10
+ export declare function useSyncMemoizedStore<T>(subscribe: Subscriber, getSnapshot: SnapshotGetter<T>): T;
@@ -0,0 +1,46 @@
1
+ 'use client';
2
+ import { useEffect, useReducer, useRef } from 'react';
3
+ /**
4
+ * Determine if the given list of dependencies has changed.
5
+ */
6
+ function useHasDepsChanged(deps) {
7
+ const ref = useRef(null);
8
+ if (ref.current === null) {
9
+ ref.current = deps;
10
+ return false;
11
+ }
12
+ if (ref.current.length === deps.length &&
13
+ !deps.some((dep, i) => !Object.is(ref.current[i], dep))) {
14
+ return false;
15
+ }
16
+ ref.current = deps;
17
+ return true;
18
+ }
19
+ /**
20
+ * Alternate for `useSyncExternalStore` which runs into infinite loops when hooks are used in `getSnapshot`
21
+ * https://github.com/facebook/react/issues/24529
22
+ */
23
+ export function useSyncMemoizedStore(subscribe, getSnapshot) {
24
+ const snapshot = useRef(null);
25
+ const [, forceRender] = useReducer((s) => s + 1, 0);
26
+ useEffect(() => {
27
+ let isMounted = true;
28
+ const unsubscribe = subscribe(() => {
29
+ if (isMounted) {
30
+ snapshot.current = getSnapshot();
31
+ forceRender();
32
+ }
33
+ });
34
+ return () => {
35
+ isMounted = false;
36
+ unsubscribe();
37
+ };
38
+ }, [subscribe, getSnapshot]);
39
+ // Since useRef does not take a dependencies array changes to dependencies need to be processed explicitly
40
+ if (useHasDepsChanged([subscribe, getSnapshot]) ||
41
+ snapshot.current === null) {
42
+ snapshot.current = getSnapshot();
43
+ }
44
+ return snapshot.current;
45
+ }
46
+ //# sourceMappingURL=client-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-utils.js","sourceRoot":"","sources":["../../src/ssr-commerce/client-utils.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAiB,SAAS,EAAE,UAAU,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AASpE;;GAEG;AACH,SAAS,iBAAiB,CAAC,IAAoB;IAC7C,MAAM,GAAG,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IAChD,IAAI,GAAG,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QACzB,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;QACnB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IACE,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;QAClC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,OAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EACxD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;IACnB,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAqB,EACrB,WAA8B;IAE9B,MAAM,QAAQ,GAAG,MAAM,CAAW,IAAI,CAAC,CAAC;IACxC,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAEpD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,IAAI,CAAC;QACrB,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,EAAE;YACjC,IAAI,SAAS,EAAE,CAAC;gBACd,QAAQ,CAAC,OAAO,GAAG,WAAW,EAAE,CAAC;gBACjC,WAAW,EAAE,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,KAAK,CAAC;YAClB,WAAW,EAAE,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;IAE7B,0GAA0G;IAC1G,IACE,iBAAiB,CAAC,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC3C,QAAQ,CAAC,OAAO,KAAK,IAAI,EACzB,CAAC;QACD,QAAQ,CAAC,OAAO,GAAG,WAAW,EAAE,CAAC;IACnC,CAAC;IAED,OAAO,QAAQ,CAAC,OAAO,CAAC;AAC1B,CAAC"}
@@ -22,7 +22,7 @@ export declare function defineCommerceEngine<TControllers extends ControllerDefi
22
22
  fetchStaticState: import("@coveo/headless/ssr-commerce").FetchStaticState<CommerceEngine, import("@coveo/headless/ssr-commerce").InferControllersMapFromDefinition<TControllers, SolutionType.listing>, import("redux").UnknownAction, import("@coveo/headless/ssr-commerce").InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, SolutionType.listing>, import("@coveo/headless/ssr-commerce").InferControllerPropsMapFromDefinitions<TControllers>>;
23
23
  hydrateStaticState: import("@coveo/headless/ssr-commerce").HydrateStaticState<CommerceEngine, import("@coveo/headless/ssr-commerce").InferControllersMapFromDefinition<TControllers, SolutionType.listing>, import("redux").UnknownAction, import("@coveo/headless/ssr-commerce").InferControllerPropsMapFromDefinitions<TControllers>>;
24
24
  build: import("@coveo/headless/ssr-commerce").Build<CommerceEngine, CommerceEngineOptions, import("@coveo/headless/ssr-commerce").InferControllersMapFromDefinition<TControllers, SolutionType.listing>, import("@coveo/headless/ssr-commerce").InferControllerPropsMapFromDefinitions<TControllers>>;
25
- setNavigatorContextProvider: (navigatorContextProvider: import("@coveo/headless/ssr").NavigatorContextProvider) => void;
25
+ setNavigatorContextProvider: (navigatorContextProvider: import("@coveo/headless/ssr-commerce").NavigatorContextProvider) => void;
26
26
  };
27
27
  searchEngineDefinition: {
28
28
  StaticStateProvider: ({ controllers, children, }: React.PropsWithChildren<{
@@ -35,7 +35,7 @@ export declare function defineCommerceEngine<TControllers extends ControllerDefi
35
35
  fetchStaticState: import("@coveo/headless/ssr-commerce").FetchStaticState<CommerceEngine, import("@coveo/headless/ssr-commerce").InferControllersMapFromDefinition<TControllers, SolutionType.search>, import("redux").UnknownAction, import("@coveo/headless/ssr-commerce").InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, SolutionType.search>, import("@coveo/headless/ssr-commerce").InferControllerPropsMapFromDefinitions<TControllers>>;
36
36
  hydrateStaticState: import("@coveo/headless/ssr-commerce").HydrateStaticState<CommerceEngine, import("@coveo/headless/ssr-commerce").InferControllersMapFromDefinition<TControllers, SolutionType.search>, import("redux").UnknownAction, import("@coveo/headless/ssr-commerce").InferControllerPropsMapFromDefinitions<TControllers>>;
37
37
  build: import("@coveo/headless/ssr-commerce").Build<CommerceEngine, CommerceEngineOptions, import("@coveo/headless/ssr-commerce").InferControllersMapFromDefinition<TControllers, SolutionType.search>, import("@coveo/headless/ssr-commerce").InferControllerPropsMapFromDefinitions<TControllers>>;
38
- setNavigatorContextProvider: (navigatorContextProvider: import("@coveo/headless/ssr").NavigatorContextProvider) => void;
38
+ setNavigatorContextProvider: (navigatorContextProvider: import("@coveo/headless/ssr-commerce").NavigatorContextProvider) => void;
39
39
  };
40
40
  standaloneEngineDefinition: {
41
41
  StaticStateProvider: ({ controllers, children, }: React.PropsWithChildren<{
@@ -48,6 +48,6 @@ export declare function defineCommerceEngine<TControllers extends ControllerDefi
48
48
  fetchStaticState: import("@coveo/headless/ssr-commerce").FetchStaticState<CommerceEngine, import("@coveo/headless/ssr-commerce").InferControllersMapFromDefinition<TControllers, SolutionType.standalone>, import("redux").UnknownAction, import("@coveo/headless/ssr-commerce").InferControllerStaticStateMapFromDefinitionsWithSolutionType<TControllers, SolutionType.standalone>, import("@coveo/headless/ssr-commerce").InferControllerPropsMapFromDefinitions<TControllers>>;
49
49
  hydrateStaticState: import("@coveo/headless/ssr-commerce").HydrateStaticState<CommerceEngine, import("@coveo/headless/ssr-commerce").InferControllersMapFromDefinition<TControllers, SolutionType.standalone>, import("redux").UnknownAction, import("@coveo/headless/ssr-commerce").InferControllerPropsMapFromDefinitions<TControllers>>;
50
50
  build: import("@coveo/headless/ssr-commerce").Build<CommerceEngine, CommerceEngineOptions, import("@coveo/headless/ssr-commerce").InferControllersMapFromDefinition<TControllers, SolutionType.standalone>, import("@coveo/headless/ssr-commerce").InferControllerPropsMapFromDefinitions<TControllers>>;
51
- setNavigatorContextProvider: (navigatorContextProvider: import("@coveo/headless/ssr").NavigatorContextProvider) => void;
51
+ setNavigatorContextProvider: (navigatorContextProvider: import("@coveo/headless/ssr-commerce").NavigatorContextProvider) => void;
52
52
  };
53
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveo/headless-react",
3
- "version": "2.1.1-pre.e48646b42a",
3
+ "version": "2.1.1-pre.ea6085c692",
4
4
  "description": "React utilities for SSR (Server Side Rendering) with headless",
5
5
  "homepage": "https://docs.coveo.com/en/headless/latest/",
6
6
  "repository": {
@@ -34,13 +34,11 @@
34
34
  "promote:npm:latest": "npm run-script -w=@coveo/release promote-npm-prod"
35
35
  },
36
36
  "dependencies": {
37
- "@coveo/headless": "3.8.2-pre.e48646b42a"
37
+ "@coveo/headless": "3.9.0-pre.ea6085c692"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@coveo/release": "1.0.0",
41
41
  "@testing-library/react": "14.3.1",
42
- "@types/react": "18.3.3",
43
- "@types/react-dom": "18.3.0",
44
42
  "@typescript-eslint/eslint-plugin": "7.17.0",
45
43
  "eslint-plugin-react": "7.35.0",
46
44
  "eslint-plugin-testing-library": "6.2.2",
@@ -52,7 +50,13 @@
52
50
  },
53
51
  "peerDependencies": {
54
52
  "react": "^18",
55
- "react-dom": "^18"
53
+ "react-dom": "^18",
54
+ "@types/react": "18.3.3",
55
+ "@types/react-dom": "18.3.0"
56
+ },
57
+ "optionalDependencies": {
58
+ "@types/react": "18.3.3",
59
+ "@types/react-dom": "18.3.0"
56
60
  },
57
61
  "engines": {
58
62
  "node": "^20.9.0 || ^22.11.0"