react-instantsearch-nextjs 1.0.16 → 1.1.0
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/cjs/InitializePromise.js +92 -97
- package/dist/cjs/InstantSearchNext.js +76 -83
- package/dist/cjs/TriggerSearch.js +40 -43
- package/dist/cjs/createInsertHTML.js +21 -25
- package/dist/cjs/htmlEscape.js +14 -18
- package/dist/cjs/index.js +7 -15
- package/dist/cjs/package.json +4 -1
- package/dist/cjs/useDynamicRouteWarning.js +17 -31
- package/dist/cjs/useInstantSearchRouting.js +61 -64
- package/dist/cjs/useNextHeaders.js +16 -21
- package/dist/es/InitializePromise.js +89 -90
- package/dist/es/InstantSearchNext.js +74 -75
- package/dist/es/TriggerSearch.js +37 -36
- package/dist/es/createInsertHTML.js +19 -18
- package/dist/es/htmlEscape.js +13 -13
- package/dist/es/index.js +1 -1
- package/dist/es/package.json +4 -0
- package/dist/es/useDynamicRouteWarning.js +15 -26
- package/dist/es/useInstantSearchRouting.js +60 -58
- package/dist/es/useNextHeaders.d.ts +9 -2
- package/dist/es/useNextHeaders.js +14 -15
- package/package.json +9 -9
- package/dist/cjs/warn.js +0 -40
- package/dist/es/warn.js +0 -33
package/dist/es/htmlEscape.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// This file was taken from the Next.js repo : https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/packages/next/src/server/htmlescape.ts
|
|
2
2
|
// License: https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/license.md
|
|
3
|
-
|
|
4
3
|
// This utility is based on https://github.com/zertosh/htmlescape
|
|
5
4
|
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
|
|
6
|
-
|
|
7
5
|
var ESCAPE_LOOKUP = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
'&': '\\u0026',
|
|
7
|
+
'>': '\\u003e',
|
|
8
|
+
'<': '\\u003c',
|
|
9
|
+
'\u2028': '\\u2028',
|
|
10
|
+
'\u2029': '\\u2029'
|
|
13
11
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
12
|
+
var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
13
|
+
function htmlEscapeJsonString(str) {
|
|
14
|
+
return str.replace(ESCAPE_REGEX, function(match) {
|
|
15
|
+
return ESCAPE_LOOKUP[match];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { ESCAPE_REGEX, htmlEscapeJsonString };
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { InstantSearchNext, createInstantSearchNextInstance } from './InstantSearchNext.js';
|
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { _ } from '@swc/helpers/cjs/_sliced_to_array.cjs';
|
|
2
|
+
import { useParams } from 'next/navigation.js';
|
|
2
3
|
|
|
3
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
4
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
6
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
7
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
9
|
-
import { useParams } from "next/navigation.js";
|
|
10
|
-
import { warn } from "./warn.js";
|
|
11
4
|
var lastParams = null;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
value = _ref3[1];
|
|
23
|
-
return params[key] !== value;
|
|
24
|
-
})) {
|
|
25
|
-
process.env.NODE_ENV === 'development' ? warn(false, "\nWe detected you may be using `<InstantSearchNext>` on a dynamic route.\n\nThis can lead to unexpected behavior, we recommend passing an `instance` prop to <InstantSearchNext>, created from the `createInstantSearchNextInstance` function.\n\nThis message can be safely ignored if you are not using dynamic routes.\n\nFor more information, see https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#dynamic-routes\n") : void 0;
|
|
5
|
+
function useDynamicRouteWarning(param) {
|
|
6
|
+
var isServer = param.isServer, isMounting = param.isMounting, instance = param.instance;
|
|
7
|
+
var params = useParams();
|
|
8
|
+
if (!isServer && isMounting.current && !instance) {
|
|
9
|
+
// Warn if lastParams and current params have the same keys but different values
|
|
10
|
+
if (lastParams && Object.keys(lastParams).length === Object.keys(params).length && Object.entries(lastParams).some(function(param) {
|
|
11
|
+
var _param = _(param, 2), key = _param[0], value = _param[1];
|
|
12
|
+
return params[key] !== value;
|
|
13
|
+
})) ;
|
|
14
|
+
lastParams = params;
|
|
26
15
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useDynamicRouteWarning };
|
|
@@ -1,60 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
7
|
-
import historyRouter from "instantsearch.js/es/lib/routers/history.js";
|
|
8
|
-
import { usePathname, useSearchParams } from "next/navigation.js";
|
|
1
|
+
import { _ as _$1 } from '@swc/helpers/cjs/_object_spread.cjs';
|
|
2
|
+
import { _ } from '@swc/helpers/cjs/_type_of.cjs';
|
|
3
|
+
import historyRouter from 'instantsearch.js/es/lib/routers/history.js';
|
|
4
|
+
import { usePathname, useSearchParams } from 'next/navigation.js';
|
|
9
5
|
import { useRef, useEffect } from 'react';
|
|
10
|
-
import { useNextHeaders } from
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
import { useNextHeaders } from './useNextHeaders.js';
|
|
7
|
+
|
|
8
|
+
function useInstantSearchRouting(passedRouting, isMounting) {
|
|
9
|
+
var isServer = typeof window === 'undefined';
|
|
10
|
+
var pathname = usePathname();
|
|
11
|
+
var searchParams = useSearchParams();
|
|
12
|
+
var routingRef = useRef(null);
|
|
13
|
+
var onUpdateRef = useRef(null);
|
|
14
|
+
var isUnmounting = useRef(false);
|
|
15
|
+
useEffect(function() {
|
|
16
|
+
if (onUpdateRef.current) {
|
|
17
|
+
onUpdateRef.current();
|
|
18
|
+
}
|
|
19
|
+
}, [
|
|
20
|
+
pathname,
|
|
21
|
+
searchParams
|
|
22
|
+
]);
|
|
23
|
+
useEffect(function() {
|
|
24
|
+
isUnmounting.current = false;
|
|
25
|
+
return function() {
|
|
26
|
+
isUnmounting.current = true;
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
var headers = useNextHeaders();
|
|
30
|
+
if (passedRouting && !routingRef.current) {
|
|
31
|
+
var browserHistoryOptions = {};
|
|
32
|
+
browserHistoryOptions.getLocation = function() {
|
|
33
|
+
if (isServer) {
|
|
34
|
+
var url = "".concat((headers === null || headers === void 0 ? void 0 : headers.get('x-forwarded-proto')) || 'http', "://").concat(headers === null || headers === void 0 ? void 0 : headers.get('host')).concat(pathname, "?").concat(searchParams);
|
|
35
|
+
return new URL(url);
|
|
36
|
+
}
|
|
37
|
+
if (isMounting.current) {
|
|
38
|
+
return new URL("".concat(window.location.protocol, "//").concat(window.location.host).concat(pathname, "?").concat(searchParams));
|
|
39
|
+
}
|
|
40
|
+
return window.location;
|
|
41
|
+
};
|
|
42
|
+
browserHistoryOptions.push = function push(url) {
|
|
43
|
+
// This is to skip the push with empty routeState on dispose as it would clear params set on a <Link>
|
|
44
|
+
if (this.isDisposed && isUnmounting.current) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
history.pushState({}, '', url);
|
|
48
|
+
};
|
|
49
|
+
browserHistoryOptions.start = function start(onUpdate) {
|
|
50
|
+
onUpdateRef.current = onUpdate;
|
|
51
|
+
};
|
|
52
|
+
routingRef.current = {};
|
|
53
|
+
if ((typeof passedRouting === "undefined" ? "undefined" : _(passedRouting)) === 'object') {
|
|
54
|
+
browserHistoryOptions = _$1({}, browserHistoryOptions, passedRouting.router);
|
|
55
|
+
routingRef.current.stateMapping = passedRouting.stateMapping;
|
|
56
|
+
}
|
|
57
|
+
routingRef.current.router = historyRouter(browserHistoryOptions);
|
|
21
58
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
isUnmounting.current = true;
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
var headers = useNextHeaders();
|
|
30
|
-
if (passedRouting && !routingRef.current) {
|
|
31
|
-
var browserHistoryOptions = {};
|
|
32
|
-
browserHistoryOptions.getLocation = function () {
|
|
33
|
-
if (isServer) {
|
|
34
|
-
var url = "".concat((headers === null || headers === void 0 ? void 0 : headers.get('x-forwarded-proto')) || 'http', "://").concat(headers === null || headers === void 0 ? void 0 : headers.get('host')).concat(pathname, "?").concat(searchParams);
|
|
35
|
-
return new URL(url);
|
|
36
|
-
}
|
|
37
|
-
if (isMounting.current) {
|
|
38
|
-
return new URL("".concat(window.location.protocol, "//").concat(window.location.host).concat(pathname, "?").concat(searchParams));
|
|
39
|
-
}
|
|
40
|
-
return window.location;
|
|
41
|
-
};
|
|
42
|
-
browserHistoryOptions.push = function push(url) {
|
|
43
|
-
// This is to skip the push with empty routeState on dispose as it would clear params set on a <Link>
|
|
44
|
-
if (this.isDisposed && isUnmounting.current) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
history.pushState({}, '', url);
|
|
48
|
-
};
|
|
49
|
-
browserHistoryOptions.start = function start(onUpdate) {
|
|
50
|
-
onUpdateRef.current = onUpdate;
|
|
51
|
-
};
|
|
52
|
-
routingRef.current = {};
|
|
53
|
-
if (_typeof(passedRouting) === 'object') {
|
|
54
|
-
browserHistoryOptions = _objectSpread(_objectSpread({}, browserHistoryOptions), passedRouting.router);
|
|
55
|
-
routingRef.current.stateMapping = passedRouting.stateMapping;
|
|
56
|
-
}
|
|
57
|
-
routingRef.current.router = historyRouter(browserHistoryOptions);
|
|
58
|
-
}
|
|
59
|
-
return routingRef.current;
|
|
60
|
-
}
|
|
59
|
+
return routingRef.current;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { useInstantSearchRouting };
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type NextHeaders = {
|
|
2
|
+
get: (name: string) => string | null;
|
|
3
|
+
has: (name: string) => boolean;
|
|
4
|
+
entries: () => IterableIterator<[string, string]>;
|
|
5
|
+
keys: () => IterableIterator<string>;
|
|
6
|
+
values: () => IterableIterator<string>;
|
|
7
|
+
forEach: (callbackfn: (value: string, key: string, parent: NextHeaders) => void) => void;
|
|
8
|
+
};
|
|
9
|
+
type Headers = NextHeaders | undefined;
|
|
3
10
|
export declare const useNextHeaders: () => Headers;
|
|
4
11
|
export {};
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import { headers } from "next/headers.js";
|
|
1
|
+
import { _ } from '@swc/helpers/cjs/_type_of.cjs';
|
|
3
2
|
import { use } from 'react';
|
|
3
|
+
|
|
4
4
|
function isPromise(obj) {
|
|
5
|
-
|
|
5
|
+
return obj !== null && ((typeof obj === "undefined" ? "undefined" : _(obj)) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} else {
|
|
15
|
-
h = nextHeaders; // assert that headers come from the synchronous nextjs function
|
|
7
|
+
var useNextHeaders = function useNextHeaders() {
|
|
8
|
+
var isServer = typeof window === 'undefined';
|
|
9
|
+
if (isServer) {
|
|
10
|
+
// Dynamic require to avoid bundling next/headers in client components
|
|
11
|
+
var nextHeadersModule = require('next/headers');
|
|
12
|
+
var nextHeaders = nextHeadersModule.headers();
|
|
13
|
+
return isPromise(nextHeaders) ? use(nextHeaders) : nextHeaders;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
return undefined;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useNextHeaders };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-instantsearch-nextjs",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "React InstantSearch SSR utilities for Next.js",
|
|
5
5
|
"types": "dist/es/index.d.ts",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -40,21 +40,21 @@
|
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
42
|
"clean": "rm -rf dist",
|
|
43
|
-
"build": "
|
|
44
|
-
"build:cjs": "BABEL_ENV=cjs babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/cjs --ignore '**/__tests__/**/*','**/__mocks__/**/*' --quiet && ../../scripts/prepare-cjs.sh",
|
|
45
|
-
"build:es:base": "BABEL_ENV=es babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/es --ignore '**/__tests__/**/*','**/__mocks__/**/*'",
|
|
46
|
-
"build:es": "yarn build:es:base --quiet",
|
|
43
|
+
"build": "BABEL_ENV=es,rollup BUILD_FORMAT=esm rollup -c rollup.config.mjs && BABEL_ENV=rollup BUILD_FORMAT=cjs rollup -c rollup.config.mjs && yarn build:types",
|
|
47
44
|
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/es",
|
|
48
45
|
"test:e2e": "playwright test",
|
|
49
46
|
"test:e2e:saucelabs": "playwright test",
|
|
50
47
|
"test:exports": "node ./__tests__/module/is-es-module.mjs && node ./__tests__/module/is-cjs-module.cjs",
|
|
51
|
-
"watch:es": "
|
|
48
|
+
"watch:es": "rollup -c rollup.config.mjs --watch"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@swc/helpers": "0.5.18"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@playwright/test": "1.49.1",
|
|
55
|
-
"instantsearch.js": "4.
|
|
55
|
+
"instantsearch.js": "4.90.0",
|
|
56
56
|
"next": "16.0.7",
|
|
57
|
-
"react-instantsearch-core": "7.
|
|
57
|
+
"react-instantsearch-core": "7.26.0",
|
|
58
58
|
"start-server-and-test": "1.15.3",
|
|
59
59
|
"ts-node": "8.4.1"
|
|
60
60
|
},
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"next": ">= 13.4 < 17",
|
|
63
63
|
"react-instantsearch": ">= 7.1.0 < 8"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "47788afa47a402d506f94f72ec0836fb36085b57"
|
|
66
66
|
}
|
package/dist/cjs/warn.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.warn = warn;
|
|
7
|
-
exports.warnCache = void 0;
|
|
8
|
-
/* eslint-disable no-console, no-empty */
|
|
9
|
-
|
|
10
|
-
var warnCache = exports.warnCache = {
|
|
11
|
-
current: {}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Logs a warning if the condition is not met.
|
|
16
|
-
* This is used to log issues in development environment only.
|
|
17
|
-
*/
|
|
18
|
-
function warn(condition, message) {
|
|
19
|
-
if (!(process.env.NODE_ENV === 'development')) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (condition) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
var sanitizedMessage = message.trim();
|
|
26
|
-
var hasAlreadyPrinted = warnCache.current[sanitizedMessage];
|
|
27
|
-
if (!hasAlreadyPrinted) {
|
|
28
|
-
warnCache.current[sanitizedMessage] = true;
|
|
29
|
-
var warning = "[react-instantsearch-nextjs] ".concat(sanitizedMessage);
|
|
30
|
-
console.warn(warning);
|
|
31
|
-
try {
|
|
32
|
-
// Welcome to debugging InstantSearch.
|
|
33
|
-
//
|
|
34
|
-
// This error was thrown as a convenience so that you can find the source
|
|
35
|
-
// of the warning that appears in the console by enabling "Pause on exceptions"
|
|
36
|
-
// in your debugger.
|
|
37
|
-
throw new Error(warning);
|
|
38
|
-
} catch (error) {}
|
|
39
|
-
}
|
|
40
|
-
}
|
package/dist/es/warn.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console, no-empty */
|
|
2
|
-
|
|
3
|
-
export var warnCache = {
|
|
4
|
-
current: {}
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Logs a warning if the condition is not met.
|
|
9
|
-
* This is used to log issues in development environment only.
|
|
10
|
-
*/
|
|
11
|
-
export function warn(condition, message) {
|
|
12
|
-
if (!(process.env.NODE_ENV === 'development')) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (condition) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
var sanitizedMessage = message.trim();
|
|
19
|
-
var hasAlreadyPrinted = warnCache.current[sanitizedMessage];
|
|
20
|
-
if (!hasAlreadyPrinted) {
|
|
21
|
-
warnCache.current[sanitizedMessage] = true;
|
|
22
|
-
var warning = "[react-instantsearch-nextjs] ".concat(sanitizedMessage);
|
|
23
|
-
console.warn(warning);
|
|
24
|
-
try {
|
|
25
|
-
// Welcome to debugging InstantSearch.
|
|
26
|
-
//
|
|
27
|
-
// This error was thrown as a convenience so that you can find the source
|
|
28
|
-
// of the warning that appears in the console by enabling "Pause on exceptions"
|
|
29
|
-
// in your debugger.
|
|
30
|
-
throw new Error(warning);
|
|
31
|
-
} catch (error) {}
|
|
32
|
-
}
|
|
33
|
-
}
|