react-instantsearch-nextjs 0.2.0 → 0.2.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.
@@ -10,6 +10,7 @@ var _utils = require("instantsearch.js/cjs/lib/utils");
10
10
  var _navigation = require("next/navigation");
11
11
  var _react = _interopRequireWildcard(require("react"));
12
12
  var _reactInstantsearchCore = require("react-instantsearch-core");
13
+ var _htmlEscape = require("./htmlEscape");
13
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
16
  var _ref2 = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
@@ -49,7 +50,7 @@ function InitializePromise() {
49
50
  inserted = true;
50
51
  return /*#__PURE__*/_react.default.createElement("script", {
51
52
  dangerouslySetInnerHTML: {
52
- __html: "window[Symbol.for(\"InstantSearchInitialResults\")] = ".concat(JSON.stringify(results))
53
+ __html: "window[Symbol.for(\"InstantSearchInitialResults\")] = ".concat((0, _htmlEscape.htmlEscapeJsonString)(JSON.stringify(results)))
53
54
  }
54
55
  });
55
56
  });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ESCAPE_REGEX = void 0;
7
+ exports.htmlEscapeJsonString = htmlEscapeJsonString;
8
+ // This file was taken from the Next.js repo : https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/packages/next/src/server/htmlescape.ts
9
+ // License: https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/license.md
10
+
11
+ // This utility is based on https://github.com/zertosh/htmlescape
12
+ // License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
13
+
14
+ var ESCAPE_LOOKUP = {
15
+ '&': "\\u0026",
16
+ '>': "\\u003e",
17
+ '<': "\\u003c",
18
+ "\u2028": "\\u2028",
19
+ "\u2029": "\\u2029"
20
+ };
21
+ var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
22
+ exports.ESCAPE_REGEX = ESCAPE_REGEX;
23
+ function htmlEscapeJsonString(str) {
24
+ return str.replace(ESCAPE_REGEX, function (match) {
25
+ return ESCAPE_LOOKUP[match];
26
+ });
27
+ }
@@ -3,6 +3,7 @@ import { walkIndex } from "instantsearch.js/es/lib/utils/index.js";
3
3
  import { ServerInsertedHTMLContext } from "next/navigation.js";
4
4
  import React, { useContext } from 'react';
5
5
  import { useInstantSearchContext, useRSCContext, wrapPromiseWithState } from 'react-instantsearch-core';
6
+ import { htmlEscapeJsonString } from "./htmlEscape.js";
6
7
  var _ref2 = /*#__PURE__*/React.createElement(React.Fragment, null);
7
8
  export function InitializePromise() {
8
9
  var _search = useInstantSearchContext();
@@ -40,7 +41,7 @@ export function InitializePromise() {
40
41
  inserted = true;
41
42
  return /*#__PURE__*/React.createElement("script", {
42
43
  dangerouslySetInnerHTML: {
43
- __html: "window[Symbol.for(\"InstantSearchInitialResults\")] = ".concat(JSON.stringify(results))
44
+ __html: "window[Symbol.for(\"InstantSearchInitialResults\")] = ".concat(htmlEscapeJsonString(JSON.stringify(results)))
44
45
  }
45
46
  });
46
47
  });
@@ -0,0 +1,2 @@
1
+ export declare const ESCAPE_REGEX: RegExp;
2
+ export declare function htmlEscapeJsonString(str: string): string;
@@ -0,0 +1,19 @@
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
+ // License: https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/license.md
3
+
4
+ // This utility is based on https://github.com/zertosh/htmlescape
5
+ // License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
6
+
7
+ var ESCAPE_LOOKUP = {
8
+ '&': "\\u0026",
9
+ '>': "\\u003e",
10
+ '<': "\\u003c",
11
+ "\u2028": "\\u2028",
12
+ "\u2029": "\\u2029"
13
+ };
14
+ export var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
15
+ export function htmlEscapeJsonString(str) {
16
+ return str.replace(ESCAPE_REGEX, function (match) {
17
+ return ESCAPE_LOOKUP[match];
18
+ });
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-instantsearch-nextjs",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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",
@@ -49,13 +49,13 @@
49
49
  "watch:es": "yarn --silent build:es:base --watch"
50
50
  },
51
51
  "devDependencies": {
52
- "instantsearch.js": "4.66.1",
52
+ "instantsearch.js": "4.68.0",
53
53
  "next": "13.5.1",
54
- "react-instantsearch-core": "7.7.1"
54
+ "react-instantsearch-core": "7.7.3"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "next": ">= 13.4 && < 15",
58
58
  "react-instantsearch": ">= 7.1.0 && < 8"
59
59
  },
60
- "gitHead": "d309ca3333476a842be080fcb01b8be925aad204"
60
+ "gitHead": "68fe2ee8544096eff8c2fbafe01a50a8acbca2b9"
61
61
  }