@zengenti/contensis-react-base 4.0.0-beta.6 → 4.0.0-beta.61

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.
Files changed (208) hide show
  1. package/README.md +14 -1
  2. package/cjs/{App-vZrUfVgQ.js → App-TTUKj85f.js} +498 -104
  3. package/cjs/App-TTUKj85f.js.map +1 -0
  4. package/cjs/{ChangePassword.container-ECjEXixF.js → ChangePassword.container-C4Du3Wb1.js} +57 -50
  5. package/cjs/ChangePassword.container-C4Du3Wb1.js.map +1 -0
  6. package/cjs/{SSRContext-DVj_QAC1.js → ContensisDeliveryApi-gN3_MHEl.js} +32 -74
  7. package/cjs/ContensisDeliveryApi-gN3_MHEl.js.map +1 -0
  8. package/cjs/CookieConstants-DfPiWCRZ.js +12 -0
  9. package/cjs/CookieConstants-DfPiWCRZ.js.map +1 -0
  10. package/{esm/CookieHelper.class-FTURFpz3.js → cjs/CookieHelper.class-Det3qfdU.js} +4 -6
  11. package/cjs/CookieHelper.class-Det3qfdU.js.map +1 -0
  12. package/cjs/{RouteLoader-D5Yg7EB5.js → RouteLoader-BM8DyfcF.js} +17 -9
  13. package/cjs/RouteLoader-BM8DyfcF.js.map +1 -0
  14. package/cjs/SSRContext-DotLlTQc.js +116 -0
  15. package/cjs/SSRContext-DotLlTQc.js.map +1 -0
  16. package/cjs/ToJs-BsWqWjdm.js +23 -0
  17. package/cjs/ToJs-BsWqWjdm.js.map +1 -0
  18. package/cjs/{VersionInfo-B_dKCubg.js → VersionInfo-zFPsvS8q.js} +3 -25
  19. package/cjs/VersionInfo-zFPsvS8q.js.map +1 -0
  20. package/cjs/client.js +62 -64
  21. package/cjs/client.js.map +1 -1
  22. package/cjs/contensis-react-base.js +246 -135
  23. package/cjs/contensis-react-base.js.map +1 -1
  24. package/cjs/i18n.js +75 -0
  25. package/cjs/i18n.js.map +1 -0
  26. package/cjs/{ToJs-C9jwV7YB.js → matchGroups-dqONU-vY.js} +2 -22
  27. package/cjs/matchGroups-dqONU-vY.js.map +1 -0
  28. package/cjs/redux.js +8 -6
  29. package/cjs/redux.js.map +1 -1
  30. package/cjs/routing.js +15 -7
  31. package/cjs/routing.js.map +1 -1
  32. package/cjs/{sagas-CbZhaRNd.js → sagas-OfBUtx74.js} +523 -370
  33. package/cjs/sagas-OfBUtx74.js.map +1 -0
  34. package/cjs/search.js +54 -29
  35. package/cjs/search.js.map +1 -1
  36. package/cjs/{selectors-wCs5fHD4.js → selectors-BrxJ8-F8.js} +27 -6
  37. package/cjs/selectors-BrxJ8-F8.js.map +1 -0
  38. package/cjs/selectors-DAQR0uZa.js +18 -0
  39. package/cjs/selectors-DAQR0uZa.js.map +1 -0
  40. package/cjs/slice-5xJMH24n.js +69 -0
  41. package/cjs/slice-5xJMH24n.js.map +1 -0
  42. package/cjs/{store-D07FOXvM.js → store-Dn7vP6G0.js} +52 -4
  43. package/cjs/store-Dn7vP6G0.js.map +1 -0
  44. package/cjs/urls-DGZlAs0y.js +25 -0
  45. package/cjs/urls-DGZlAs0y.js.map +1 -0
  46. package/cjs/user.js +20 -17
  47. package/cjs/user.js.map +1 -1
  48. package/cjs/util-wQwG9vit.js +148 -0
  49. package/cjs/util-wQwG9vit.js.map +1 -0
  50. package/cjs/util.js +80 -22
  51. package/cjs/util.js.map +1 -1
  52. package/cjs/{version-B7XFkBhY.js → version-2FamXHhj.js} +15 -16
  53. package/cjs/version-2FamXHhj.js.map +1 -0
  54. package/cjs/{version-CM-bJ62L.js → version-rFG9Y6_B.js} +2 -2
  55. package/cjs/{version-CM-bJ62L.js.map → version-rFG9Y6_B.js.map} +1 -1
  56. package/esm/{App-DLZweVSp.js → App-DaHtrw85.js} +458 -65
  57. package/esm/App-DaHtrw85.js.map +1 -0
  58. package/esm/{ChangePassword.container-BgzIy8dA.js → ChangePassword.container-CUBtn82K.js} +19 -13
  59. package/esm/ChangePassword.container-CUBtn82K.js.map +1 -0
  60. package/esm/{SSRContext-BE8ElZ3X.js → ContensisDeliveryApi-CvEoOLCl.js} +30 -67
  61. package/esm/ContensisDeliveryApi-CvEoOLCl.js.map +1 -0
  62. package/esm/CookieConstants-DEmbwzYr.js +7 -0
  63. package/esm/CookieConstants-DEmbwzYr.js.map +1 -0
  64. package/{cjs/CookieHelper.class-C3Eqoze9.js → esm/CookieHelper.class-C6rTRl_1.js} +2 -14
  65. package/esm/CookieHelper.class-C6rTRl_1.js.map +1 -0
  66. package/esm/{RouteLoader-xeQBXywk.js → RouteLoader-BwDPahRW.js} +14 -6
  67. package/esm/RouteLoader-BwDPahRW.js.map +1 -0
  68. package/esm/SSRContext-CYxBWky3.js +106 -0
  69. package/esm/SSRContext-CYxBWky3.js.map +1 -0
  70. package/esm/ToJs-BnRRHk6f.js +17 -0
  71. package/esm/ToJs-BnRRHk6f.js.map +1 -0
  72. package/esm/{VersionInfo-Cno7K0OA.js → VersionInfo-By2ZCZOh.js} +4 -24
  73. package/esm/VersionInfo-By2ZCZOh.js.map +1 -0
  74. package/esm/client.js +62 -63
  75. package/esm/client.js.map +1 -1
  76. package/esm/contensis-react-base.js +239 -130
  77. package/esm/contensis-react-base.js.map +1 -1
  78. package/esm/i18n.js +64 -0
  79. package/esm/i18n.js.map +1 -0
  80. package/esm/{ToJs-CNzfvyxJ.js → matchGroups-_w8BwzCC.js} +3 -18
  81. package/esm/matchGroups-_w8BwzCC.js.map +1 -0
  82. package/esm/redux.js +11 -8
  83. package/esm/redux.js.map +1 -1
  84. package/esm/routing.js +14 -7
  85. package/esm/routing.js.map +1 -1
  86. package/esm/{sagas-xJU-zOpn.js → sagas-BZWjx5by.js} +511 -357
  87. package/esm/sagas-BZWjx5by.js.map +1 -0
  88. package/esm/search.js +73 -47
  89. package/esm/search.js.map +1 -1
  90. package/esm/{selectors-DO2ocdOp.js → selectors-8ROQrTd7.js} +25 -7
  91. package/esm/selectors-8ROQrTd7.js.map +1 -0
  92. package/esm/selectors-DcmvOeX2.js +10 -0
  93. package/esm/selectors-DcmvOeX2.js.map +1 -0
  94. package/esm/slice-C6JLQik8.js +63 -0
  95. package/esm/slice-C6JLQik8.js.map +1 -0
  96. package/esm/{store-3u0RzHZ0.js → store-DSjRYsM2.js} +52 -5
  97. package/esm/store-DSjRYsM2.js.map +1 -0
  98. package/esm/urls-tLxo_skx.js +22 -0
  99. package/esm/urls-tLxo_skx.js.map +1 -0
  100. package/esm/user.js +9 -6
  101. package/esm/user.js.map +1 -1
  102. package/esm/util-BafFLYzn.js +136 -0
  103. package/esm/util-BafFLYzn.js.map +1 -0
  104. package/esm/util.js +58 -14
  105. package/esm/util.js.map +1 -1
  106. package/esm/{version-BlsI7hX2.js → version-B75wA6Te.js} +16 -16
  107. package/esm/version-B75wA6Te.js.map +1 -0
  108. package/esm/{version-wnf-TITV.js → version-BQAL8sQO.js} +2 -2
  109. package/esm/{version-wnf-TITV.js.map → version-BQAL8sQO.js.map} +1 -1
  110. package/i18n/package.json +5 -0
  111. package/models/app/pages/VersionInfo/components/VersionInfo.d.ts +1 -1
  112. package/models/app/pages/VersionInfo/components/VersionInfo.styled.d.ts +0 -1
  113. package/models/i18n/index.d.ts +5 -0
  114. package/models/i18n/redux/sagas.d.ts +19 -0
  115. package/models/i18n/redux/selectors.d.ts +11 -0
  116. package/models/i18n/redux/slice.d.ts +198 -0
  117. package/models/i18n/routes.d.ts +8 -0
  118. package/models/i18n/useI18n.hook.d.ts +20 -0
  119. package/models/index.d.ts +1 -0
  120. package/models/models/AppState.d.ts +2 -0
  121. package/models/models/ContentTypeMapping.d.ts +5 -0
  122. package/models/models/Locales.d.ts +11 -0
  123. package/models/models/MatchedRoute.d.ts +5 -1
  124. package/models/models/RouteComponent.d.ts +0 -1
  125. package/models/models/SSRContext.d.ts +4 -4
  126. package/models/models/StaticRoute.d.ts +11 -0
  127. package/models/models/WithEvents.d.ts +8 -0
  128. package/models/models/config/AppConfig.d.ts +2 -0
  129. package/models/models/config/I18n.d.ts +38 -0
  130. package/models/models/config/ServerConfig.d.ts +14 -0
  131. package/models/redux/index.d.ts +2 -1
  132. package/models/redux/sagas/index.d.ts +3 -1
  133. package/models/redux/sagas/injector.d.ts +13 -0
  134. package/models/redux/store/injectors/index.d.ts +26 -0
  135. package/models/redux/store/injectors/inject.d.ts +24 -0
  136. package/models/redux/store/injectors/util.d.ts +2 -0
  137. package/models/redux/store/store.d.ts +13 -4
  138. package/models/redux/util.d.ts +1 -1
  139. package/models/routing/components/RouteLoader.d.ts +3 -3
  140. package/models/routing/httpContext.d.ts +0 -1
  141. package/models/routing/index.d.ts +1 -0
  142. package/models/routing/redux/actions.d.ts +1 -1
  143. package/models/routing/redux/invokeSearch.d.ts +22 -0
  144. package/models/routing/redux/selectors.d.ts +47 -4
  145. package/models/routing/util/expressions.d.ts +1 -1
  146. package/models/routing/util/find-contenttype-mapping.d.ts +3 -1
  147. package/models/search/containers/withListing.d.ts +1 -1
  148. package/models/search/containers/withSearch.d.ts +1 -1
  149. package/models/search/models/Queries.d.ts +3 -5
  150. package/models/search/models/Search.d.ts +43 -13
  151. package/models/search/models/SearchActions.d.ts +61 -18
  152. package/models/search/models/SearchProps.d.ts +11 -10
  153. package/models/search/models/SearchState.d.ts +23 -2
  154. package/models/search/models/SearchUtil.d.ts +3 -3
  155. package/models/search/redux/getIn.d.ts +2 -2
  156. package/models/search/redux/reducers.d.ts +3 -4
  157. package/models/search/redux/sagas.d.ts +13 -14
  158. package/models/search/redux/schema.d.ts +3 -3
  159. package/models/search/redux/selectors.d.ts +64 -42
  160. package/models/search/redux/util.d.ts +10 -1
  161. package/models/search/search/ContensisDeliveryApi.d.ts +6 -26
  162. package/models/search/search/expressions.d.ts +6 -4
  163. package/models/search/search/util.d.ts +9 -7
  164. package/models/search/transformations/state-to-queryparams.mapper.d.ts +1 -1
  165. package/models/server/features/linkdepth-api/search.d.ts +1 -1
  166. package/models/server/features/response-handler/render-stream.d.ts +2 -4
  167. package/models/server/features/static-assets/index.d.ts +4 -3
  168. package/models/server/internalServer.d.ts +1 -2
  169. package/models/server/middleware/subsiteDebug.d.ts +11 -0
  170. package/models/server/root.d.ts +3 -0
  171. package/models/server/util/bundles.d.ts +9 -9
  172. package/models/server/util/jsx.d.ts +2 -14
  173. package/models/user/hocs/withRegistration.d.ts +1 -1
  174. package/models/util/CachedDeliveryApi.d.ts +8 -2
  175. package/models/util/ContensisDeliveryApi.d.ts +2 -4
  176. package/models/util/NoSSR.d.ts +6 -0
  177. package/models/util/SSRContext.d.ts +3 -19
  178. package/models/util/donotuse_useHistory.d.ts +6 -0
  179. package/models/util/errors.d.ts +16 -0
  180. package/models/util/index.d.ts +7 -2
  181. package/models/util/subsite.d.ts +12 -0
  182. package/models/util/urls.d.ts +1 -2
  183. package/models/util/useIsClient.d.ts +6 -0
  184. package/package.json +39 -38
  185. package/cjs/App-vZrUfVgQ.js.map +0 -1
  186. package/cjs/ChangePassword.container-ECjEXixF.js.map +0 -1
  187. package/cjs/CookieHelper.class-C3Eqoze9.js.map +0 -1
  188. package/cjs/RouteLoader-D5Yg7EB5.js.map +0 -1
  189. package/cjs/SSRContext-DVj_QAC1.js.map +0 -1
  190. package/cjs/ToJs-C9jwV7YB.js.map +0 -1
  191. package/cjs/VersionInfo-B_dKCubg.js.map +0 -1
  192. package/cjs/sagas-CbZhaRNd.js.map +0 -1
  193. package/cjs/selectors-wCs5fHD4.js.map +0 -1
  194. package/cjs/store-D07FOXvM.js.map +0 -1
  195. package/cjs/version-B7XFkBhY.js.map +0 -1
  196. package/esm/App-DLZweVSp.js.map +0 -1
  197. package/esm/ChangePassword.container-BgzIy8dA.js.map +0 -1
  198. package/esm/CookieHelper.class-FTURFpz3.js.map +0 -1
  199. package/esm/RouteLoader-xeQBXywk.js.map +0 -1
  200. package/esm/SSRContext-BE8ElZ3X.js.map +0 -1
  201. package/esm/ToJs-CNzfvyxJ.js.map +0 -1
  202. package/esm/VersionInfo-Cno7K0OA.js.map +0 -1
  203. package/esm/sagas-xJU-zOpn.js.map +0 -1
  204. package/esm/selectors-DO2ocdOp.js.map +0 -1
  205. package/esm/store-3u0RzHZ0.js.map +0 -1
  206. package/esm/version-BlsI7hX2.js.map +0 -1
  207. package/models/redux/store/injectors.d.ts +0 -31
  208. package/models/search/search/ToJs.d.ts +0 -4
@@ -1,23 +1,26 @@
1
- import { c as cachedSearch, S as SSRContextProvider, d as deliveryApi } from './SSRContext-BE8ElZ3X.js';
1
+ import { c as cachedSearch, d as deliveryApi } from './ContensisDeliveryApi-CvEoOLCl.js';
2
2
  import { Query as Query$1 } from 'contensis-delivery-api';
3
3
  import React from 'react';
4
4
  import { Provider } from 'react-redux';
5
+ import { a as actions } from './slice-C6JLQik8.js';
5
6
  import mapJson from 'jsonpath-mapper';
6
- import { a8 as defaultExpressions, a9 as termExpressions, aa as contentTypeIdExpression, ab as filterExpressions, ac as orderByExpression, ad as customWhereExpressions, ae as cloneDeep } from './sagas-xJU-zOpn.js';
7
+ import { a7 as defaultExpressions, a8 as termExpressions, a9 as contentTypeIdExpression, aa as filterExpressions, ab as orderByExpression, ac as customWhereExpressions, ad as cloneDeep } from './sagas-BZWjx5by.js';
7
8
  import 'reselect';
8
9
  import 'immer';
9
10
  import 'deep-equal';
10
11
  import 'deepmerge';
11
12
  import 'query-string';
12
13
  import { Op, Query } from 'contensis-core-api';
13
- import { s as setCachingHeaders, u as url } from './VersionInfo-Cno7K0OA.js';
14
+ import { s as setCachingHeaders, u as urls } from './urls-tLxo_skx.js';
14
15
  import 'isomorphic-fetch';
15
16
  import express from 'express';
16
17
  import http from 'http';
17
18
  import httpProxy from 'http-proxy';
19
+ import { s as shorten, c as createLocaleRoutes, h as history, p as pickProject, r as rootSaga } from './App-DaHtrw85.js';
20
+ export { A as ReactApp } from './App-DaHtrw85.js';
18
21
  import fs from 'fs';
19
22
  import path from 'path';
20
- import { path as path$1 } from 'app-root-path';
23
+ import appRootPath from 'app-root-path';
21
24
  import { renderToPipeableStream, renderToString } from 'react-dom/server';
22
25
  import { matchRoutes } from 'react-router-dom';
23
26
  import { Helmet } from 'react-helmet';
@@ -25,32 +28,38 @@ import { ServerStyleSheet } from 'styled-components';
25
28
  import serialize from 'serialize-javascript';
26
29
  import { noop, identity } from 'lodash';
27
30
  import { buildCleaner } from 'lodash-clean';
28
- import { a as Cookies } from './CookieHelper.class-FTURFpz3.js';
31
+ import { a as Cookies } from './CookieHelper.class-C6rTRl_1.js';
29
32
  import cookiesMiddleware from 'universal-cookie-express';
30
- import { c as createStore } from './store-3u0RzHZ0.js';
31
- import { h as history, p as pickProject, r as rootSaga } from './App-DLZweVSp.js';
32
- export { A as ReactApp } from './App-DLZweVSp.js';
33
- import { s as setVersionStatus, d as setVersion } from './version-BlsI7hX2.js';
34
- import { a3 as selectSurrogateKeys, a4 as selectSsrApiCalls, h as selectRouteEntry, n as selectCurrentProject, g as getImmutableOrJS, d as setCurrentProject, K as selectCurrentSearch } from './selectors-DO2ocdOp.js';
35
- import { H as HttpContext, m as mergeStaticRoutes } from './RouteLoader-xeQBXywk.js';
33
+ import { c as createStore } from './store-DSjRYsM2.js';
34
+ import { s as setVersionStatus, c as setVersion } from './version-B75wA6Te.js';
35
+ import { a6 as selectSurrogateKeys, a7 as selectSsrApiCalls, j as selectRouteEntry, f as selectCurrentProject, g as getImmutableOrJS, s as setCurrentProject, F as selectCurrentSearch } from './selectors-8ROQrTd7.js';
36
+ import { H as HttpContext, m as mergeStaticRoutes } from './RouteLoader-BwDPahRW.js';
36
37
  import { Transform } from 'stream';
37
38
  import { ChunkExtractor, ChunkExtractorManager } from '@loadable/server';
38
39
  import chalk from 'chalk';
39
40
  import minifyCssString from 'minify-css-string';
40
41
  import { CookiesProvider } from 'react-cookie';
42
+ import { HelmetProvider } from 'react-helmet-async';
41
43
  import { StaticRouter } from 'react-router-dom/server';
44
+ import { S as SSRContextProvider, g as getSubsitePath } from './SSRContext-CYxBWky3.js';
45
+ import './VersionInfo-By2ZCZOh.js';
46
+ import './CookieConstants-DEmbwzYr.js';
47
+ import '@reduxjs/toolkit';
42
48
  import 'loglevel';
43
49
  import '@redux-saga/core/effects';
50
+ import './version-BQAL8sQO.js';
51
+ import './util-BafFLYzn.js';
52
+ import './selectors-DcmvOeX2.js';
44
53
  import './_commonjsHelpers-BFTU3MAI.js';
45
- import './version-wnf-TITV.js';
54
+ import 'history';
55
+ import 'await-to-js';
56
+ import './ChangePassword.container-CUBtn82K.js';
57
+ import './matchGroups-_w8BwzCC.js';
58
+ import './ToJs-BnRRHk6f.js';
46
59
  import 'redux';
47
60
  import 'redux-thunk';
48
61
  import 'redux-saga';
49
62
  import 'redux-injectors-19';
50
- import 'history';
51
- import 'await-to-js';
52
- import './ChangePassword.container-BgzIy8dA.js';
53
- import './ToJs-CNzfvyxJ.js';
54
63
 
55
64
  /**
56
65
  * Util class holds our search results helper boilerplate methods
@@ -610,42 +619,66 @@ const makeLinkDepthMiddleware = ({
610
619
  }
611
620
  };
612
621
 
622
+ /**
623
+ * Development proxy for Subsite PoC
624
+ * Catch all routes before they hit CRB handlers
625
+ * and rewrite them to include the subsite base path,
626
+ * this allows us to run the subsite in a subfolder in development
627
+ * In production we will handle this with a path rewrite in the Cloud Dashboard site configuration,
628
+ * @param subsitePath the content base path we will rewrite to
629
+ * @param exceptions an array of path prefixes to ignore when rewriting, useful for ignoring assets that do not live in the subsite base path
630
+ */
631
+ const subsiteDebugMiddleware = (subsitePath, exceptions = []) => (req, res, next) => {
632
+ if (!subsitePath || req.hostname !== 'localhost' || req.path.startsWith('/api/') || exceptions.some(exception => req.path.startsWith(exception))) return next();
633
+ if (!req.path.startsWith(`${subsitePath}/`)) {
634
+ console.warn(`[subsite-debug-middleware] Rewriting (${subsitePath})${req.url}`);
635
+ if (req.path === '/' || req.path === subsitePath) req.url = subsitePath;else req.url = `${subsitePath}${req.url}`;
636
+ res.setHeader('x-crb-subsite-content-path', req.url);
637
+
638
+ // Important to set the subsite_path header as this drives the subsite-scoped routing logic
639
+ req.headers['subsite_path'] = subsitePath;
640
+ }
641
+ next();
642
+ };
643
+
613
644
  const servers$1 = SERVERS; /* global SERVERS */
614
645
  const project = PROJECT; /* global PROJECT */
615
646
  const alias$1 = ALIAS; /* global ALIAS */
616
- const deliveryApiHostname = url(alias$1, project).api;
647
+ const deliveryApiHostname = urls(alias$1, project).api;
648
+ const proxyTimeoutMs = 45_000;
617
649
  const assetProxy = httpProxy.createProxyServer();
618
650
  const deliveryProxy = httpProxy.createProxyServer();
619
651
  const reverseProxies = (app, reverseProxyPaths = []) => {
620
652
  deliveryApiProxy(deliveryProxy, app);
621
- app.all(reverseProxyPaths, (req, res) => {
622
- const target = req.hostname.indexOf('preview-') || req.hostname.indexOf('preview.') || req.hostname === 'localhost' ? servers$1.previewIis || servers$1.iis : servers$1.iis;
653
+ app.all(reverseProxyPaths.map(proxyPath =>
654
+ // Patch to update paths for express v5
655
+ proxyPath.endsWith('/*') ? `${proxyPath.slice(0, -2)}/{*splat}` : proxyPath.endsWith('/**') ? `${proxyPath.slice(0, -3)}/{*splat}` : proxyPath), (req, res) => {
656
+ const target = req.hostname.includes('preview-') || req.hostname.includes('preview.') || req.hostname === 'localhost' ? servers$1.previewIis || servers$1.iis : servers$1.iis;
623
657
  assetProxy.web(req, res, {
624
658
  target,
625
- changeOrigin: true
626
- });
627
- assetProxy.on('error', e => {
628
- /* eslint-disable no-console */
629
- console.log(`Proxy Request for ${req.path} HostName:${req.hostname} failed with ${e}`);
630
- /* eslint-enable no-console */
659
+ changeOrigin: true,
660
+ proxyTimeout: proxyTimeoutMs,
661
+ timeout: proxyTimeoutMs
631
662
  });
632
663
  });
664
+ assetProxy.on('error', (e, req) => {
665
+ console.log(`[assetProxy] "${req.method} ${req.url}" host: ${req.headers.host} failed with ${e}`);
666
+ });
633
667
  };
634
668
  const deliveryApiProxy = (apiProxy, app) => {
635
669
  // This is just here to stop cors requests on localhost. In Production this is mapped using varnish.
636
- app.all(['/api/delivery/*', '/api/forms/*', '/api/image/*', '/authenticate/*'], (req, res) => {
637
- /* eslint-disable no-console */
638
- console.log(`Proxying api request to ${servers$1.alias}`);
670
+ app.all(['/api/delivery/{*splat}', '/api/forms/{*splat}', '/api/image/{*splat}', '/authenticate/{*splat}'], (req, res) => {
671
+ console.log(`[apiProxy] "${req.method} ${shorten(req.url)}" target: ${servers$1.alias}`);
639
672
  apiProxy.web(req, res, {
640
673
  target: deliveryApiHostname,
641
- changeOrigin: true
642
- });
643
- apiProxy.on('error', e => {
644
- /* eslint-disable no-console */
645
- console.log(`Proxy request for ${req.path} HostName:${req.hostname} failed with ${e}`);
646
- /* eslint-enable no-console */
674
+ changeOrigin: true,
675
+ proxyTimeout: proxyTimeoutMs,
676
+ timeout: proxyTimeoutMs
647
677
  });
648
678
  });
679
+ apiProxy.on('error', (e, req) => {
680
+ console.log(`[apiProxy] "${req.method} ${req.url}" host: ${req.headers.host} failed with ${e}`);
681
+ });
649
682
  };
650
683
 
651
684
  const CacheDuration = {
@@ -720,9 +753,8 @@ const resolveStartupMiddleware = ({
720
753
  if (maxage) res.set('Cache-Control', `public, max-age=${maxage}`);
721
754
  res.sendFile(startupFileLocation);
722
755
  } catch (sendFileError) {
723
- // eslint-disable-next-line no-console
724
756
  console.log(`Unable to send file startup.js at '${startupFileLocation}'`, sendFileError);
725
- next();
757
+ res.status(404).send();
726
758
  }
727
759
  } else {
728
760
  next();
@@ -730,8 +762,11 @@ const resolveStartupMiddleware = ({
730
762
  };
731
763
 
732
764
  // Serving static assets
765
+ const {
766
+ path: appPath
767
+ } = appRootPath;
733
768
  const staticAssets = (app, {
734
- appRootPath = path$1,
769
+ appRootPath = appPath,
735
770
  scripts = {},
736
771
  startupScriptFilename = 'startup.js',
737
772
  staticFolderPath = 'static',
@@ -750,9 +785,7 @@ const staticAssets = (app, {
750
785
  maxage: CacheDuration.static,
751
786
  startupScriptFilename: scripts.startup || startupScriptFilename,
752
787
  staticFolderPath
753
- }),
754
- // eslint-disable-next-line import/no-named-as-default-member
755
- express.static(`dist/${staticFolderPath}`, {
788
+ }), express.static(`dist/${staticFolderPath}`, {
756
789
  // these maxage values are different in config but the same in runtime,
757
790
  // this one is somehow converted and should end up being the same as CacheDuration.static
758
791
  maxAge: CacheDuration.expressStatic
@@ -802,32 +835,59 @@ const handleResponse = (request, response, content, send = 'send') => {
802
835
  * @param response the express Response object
803
836
  * @param stream all chunks are piped to this stream to add additional style elements to each streamed chunk
804
837
  */
805
- const renderStream = (getContextHtml, jsx, response, stream) => {
806
- let header = '';
807
- let footer = '';
838
+ const renderStream = (getContextHtml, jsx, request, response, stream) => {
839
+ // Store timeout reference for cleanup on normal or abnormal termination
840
+ let timeoutId = null;
841
+ const disposeTimeout = () => {
842
+ if (timeoutId) {
843
+ clearTimeout(timeoutId);
844
+ timeoutId = null;
845
+ }
846
+ };
847
+
848
+ // Only used for abnormal termination
849
+ const abortCleanup = err => {
850
+ disposeTimeout();
851
+ stream.destroy(err instanceof Error ? err : undefined);
852
+ abort();
853
+ };
854
+
855
+ // Guard against client disconnect
856
+ request.on('close', () => abortCleanup());
857
+
858
+ // Guard against transform errors
859
+ stream.on('error', err => {
860
+ abortCleanup(err);
861
+ if (!response.headersSent) response.destroy(err);
862
+ });
808
863
  const {
809
864
  abort,
810
865
  pipe
811
866
  } = renderToPipeableStream(jsx, {
812
867
  onShellReady() {
813
- const html = getContextHtml();
868
+ const html = getContextHtml(false);
814
869
  if (!html) {
815
870
  // this means we have finished with the response already
816
- abort();
871
+ abortCleanup();
817
872
  } else {
818
- [header, footer] = html.split('{{APP}}');
873
+ const header = html.split('{{APP}}')[0];
819
874
  response.setHeader('content-type', 'text/html; charset=utf-8');
820
875
  stream.write(header);
821
876
  pipe(stream);
822
877
  }
823
878
  },
824
879
  onAllReady() {
880
+ const footer = getContextHtml(true).split('{{APP}}')[1];
825
881
  stream.write(footer);
882
+ disposeTimeout(); // Clear the timeout, let stream end naturally
826
883
  },
827
884
  onShellError(error) {
828
- response.statusCode = 500;
829
- response.setHeader('content-type', 'text/html; charset=utf-8');
830
- response.send('<h1>Something went wrong</h1>');
885
+ abortCleanup(error); // Abnormal - destroy everything
886
+ if (!response.headersSent) {
887
+ response.statusCode = 500;
888
+ response.setHeader('content-type', 'text/html; charset=utf-8');
889
+ response.send('<h1>Something went wrong</h1>');
890
+ }
831
891
  console.error(`[renderToPipeableStream:onShellError]`, error);
832
892
  },
833
893
  onError(error) {
@@ -835,10 +895,13 @@ const renderStream = (getContextHtml, jsx, response, stream) => {
835
895
  }
836
896
  });
837
897
 
838
- // Abandon and switch to client rendering if enough time passes.
898
+ // Abandon and switch to client rendering after 30s.
839
899
  // Try lowering this to see the client recover.
840
- setTimeout(() => abort(), 30 * 1000);
841
- stream === null || stream === void 0 || stream.pipe(response);
900
+ timeoutId = setTimeout(() => {
901
+ timeoutId = null;
902
+ abortCleanup();
903
+ }, 30_000);
904
+ stream.pipe(response);
842
905
  };
843
906
 
844
907
  /**
@@ -878,6 +941,23 @@ const styledComponentsStream = sheet => {
878
941
  this.push(styledCSS + renderedHtml);
879
942
  }
880
943
  callback();
944
+ },
945
+ destroy(err, callback) {
946
+ // Called on both stream.destroy() and natural end
947
+ // Stops the sheet intercepting styles & releases its references
948
+
949
+ // try/catch is required if sheet.seal() throws for any reason,
950
+ // callback(err) must still be called, as Node.js stream internals depend
951
+ // on it to complete teardown. Omitting it causes the stream to hang.
952
+ try {
953
+ sheet.seal();
954
+ } catch (sealErr) {
955
+ // Catch any errors from sealing the sheet, we MUST always call the
956
+ // callback to prevent hanging the stream
957
+
958
+ console.error('[styledComponentsStream] sheet.seal() failed - styles may leak:', sealErr);
959
+ }
960
+ callback(err);
881
961
  }
882
962
  });
883
963
  return readerWriter;
@@ -930,7 +1010,8 @@ const loadableChunkExtractors = () => {
930
1010
  statsFile: path.resolve('dist/legacy/loadable-stats.json')
931
1011
  });
932
1012
  } catch (e) {
933
- console.info('@loadable/server legacy ChunkExtractor not available');
1013
+ // legacy bundling deprecated in v4
1014
+ // console.info('@loadable/server legacy ChunkExtractor not available');
934
1015
  }
935
1016
  commonLoadableExtractor.addChunk = chunk => {
936
1017
  var _modern, _legacy, _legacy2;
@@ -1038,6 +1119,7 @@ const unhandledExceptionHandler = (handleExceptions = handleDefaultEvents) => {
1038
1119
  }
1039
1120
  };
1040
1121
 
1122
+ const logPrefix = '[addHeaders]';
1041
1123
  const addStandardHeaders = (state, response, packagejson, groups) => {
1042
1124
  if (state) {
1043
1125
  try {
@@ -1051,14 +1133,14 @@ const addStandardHeaders = (state, response, packagejson, groups) => {
1051
1133
  // - add `any-update` header that will indiscriminately
1052
1134
  // invalidate the SSR page cache when any content is updated
1053
1135
  const addAnyUpdateHeader = routingSurrogateKeys.length >= 2000 || response.statusCode >= 400 || anyApiError;
1054
- console.info(`[addStandardHeaders] ${addAnyUpdateHeader ? anyUpdateHeader : routingSurrogateKeys.length} surrogate keys for ${response.req.url}`);
1136
+ console.info(`${logPrefix} ${addAnyUpdateHeader ? anyUpdateHeader : routingSurrogateKeys.length} surrogate keys for ${response.req.url}`);
1055
1137
  const surrogateKeys = addAnyUpdateHeader ? anyUpdateHeader : routingSurrogateKeys.join(' ');
1056
1138
  const surrogateKeyHeader = `${packagejson.name}-app ${surrogateKeys}`;
1057
1139
  response.setHeader('surrogate-key', surrogateKeyHeader);
1058
1140
  addVarnishAuthenticationHeaders(state, response, groups);
1059
1141
  response.setHeader('surrogate-control', `max-age=${getCacheDuration(response.statusCode)}`);
1060
1142
  } catch (e) {
1061
- console.info('[addStandardHeaders] Error adding headers', e.message);
1143
+ console.info(`${logPrefix} Error adding headers`, e.message);
1062
1144
  }
1063
1145
  }
1064
1146
  };
@@ -1071,14 +1153,13 @@ const addVarnishAuthenticationHeaders = (state, response, groups = {}) => {
1071
1153
  globalGroups,
1072
1154
  allowedGroups
1073
1155
  } = groups;
1074
- // console.info(globalGroups, allowedGroups);
1075
1156
  let allGroups = Array.from(globalGroups && globalGroups[project] || {});
1076
1157
  if (stateEntry && getImmutableOrJS(stateEntry, ['authentication', 'isLoginRequired']) && allowedGroups && allowedGroups[project]) {
1077
1158
  allGroups = [...allGroups, ...allowedGroups[project]];
1078
1159
  }
1079
1160
  response.header('x-contensis-viewer-groups', allGroups.join('|'));
1080
1161
  } catch (e) {
1081
- console.info('Error adding authentication header', e);
1162
+ console.info(`${logPrefix} Error adding authentication header`, e);
1082
1163
  }
1083
1164
  }
1084
1165
  };
@@ -1104,14 +1185,17 @@ const replaceHtml = ({
1104
1185
  let responseHTML = '';
1105
1186
  // Serve a blank HTML page with client scripts to load the app in the browser
1106
1187
  if (accessMethod.DYNAMIC) {
1107
- responseHTML = templateHTML.replace('{{TITLE}}', '').replace('{{SEO_CRITICAL_METADATA}}', '').replace('{{CRITICAL_CSS}}', '').replace('{{APP}}', '').replace('{{LOADABLE_CHUNKS}}', bundleTags).replace('{{REDUX_DATA}}', state);
1188
+ responseHTML = templateHTML.replace('{{TITLE}}', '').replace('{{SEO_CRITICAL_METADATA}}', '').replace('{{CRITICAL_CSS}}', '').replace('{{APP}}', '')
1189
+ // .replace('{{LOADABLE_CHUNKS}}', bundleTags)
1190
+ .replace('{{REDUX_DATA}}', state);
1108
1191
  }
1109
1192
 
1110
1193
  // Page fragment served with client scripts and redux data that hydrate the app client side
1111
1194
  else if (accessMethod.FRAGMENT && !accessMethod.STATIC) {
1112
1195
  responseHTML = templateHTMLFragment.replace('{{TITLE}}', title).replace('{{SEO_CRITICAL_METADATA}}', metadata).replace('{{CRITICAL_CSS}}', minifyCssString(styleTags))
1113
1196
  //.replace('{{APP}}', html)
1114
- .replace('{{LOADABLE_CHUNKS}}', bundleTags).replace('{{REDUX_DATA}}', state);
1197
+ // .replace('{{LOADABLE_CHUNKS}}', bundleTags)
1198
+ .replace('{{REDUX_DATA}}', state);
1115
1199
  }
1116
1200
 
1117
1201
  // Full HTML page served statically
@@ -1125,7 +1209,8 @@ const replaceHtml = ({
1125
1209
  else if (!accessMethod.FRAGMENT && !accessMethod.STATIC) {
1126
1210
  responseHTML = templateHTML.replace('{{TITLE}}', title).replace('{{SEO_CRITICAL_METADATA}}', metadata).replace('{{CRITICAL_CSS}}', styleTags)
1127
1211
  //.replace('{{APP}}', html)
1128
- .replace('{{LOADABLE_CHUNKS}}', bundleTags).replace('{{REDUX_DATA}}', state);
1212
+ // .replace('{{LOADABLE_CHUNKS}}', bundleTags)
1213
+ .replace('{{REDUX_DATA}}', state);
1129
1214
  }
1130
1215
 
1131
1216
  // If react-helmet htmlAttributes are being used,
@@ -1134,7 +1219,12 @@ const replaceHtml = ({
1134
1219
  if (htmlAttributes) {
1135
1220
  responseHTML = responseHTML.replace(/<html?.+?>/, `<html ${htmlAttributes}>`);
1136
1221
  }
1137
- return html ? responseHTML.replace('{{APP}}', html) : responseHTML;
1222
+ responseHTML = html ? responseHTML.replace('{{APP}}', html) : responseHTML;
1223
+
1224
+ // Only replace bundle tags at the very end when we have rendered and are
1225
+ // streaming out the HTML "footer"
1226
+ if (bundleTags) responseHTML = responseHTML.replace('{{LOADABLE_CHUNKS}}', bundleTags);
1227
+ return responseHTML;
1138
1228
  };
1139
1229
 
1140
1230
  /**
@@ -1146,13 +1236,15 @@ const replaceHtml = ({
1146
1236
  */
1147
1237
  const ssrJsxProducer = (ReactApp, {
1148
1238
  providers,
1149
- props,
1150
- ssrAssets
1239
+ props
1240
+ // ssrAssets,
1151
1241
  }) => {
1152
1242
  var _providers$styledComp;
1153
1243
  // Recast ChunkExtractorManager to avoid TS error `Property 'children' does not exist on type...`
1154
1244
  const ChunkExtractor = ChunkExtractorManager;
1155
- const jsx = /*#__PURE__*/React.createElement(ChunkExtractor, {
1245
+ const jsx = /*#__PURE__*/React.createElement(HelmetProvider, {
1246
+ context: providers.helmet
1247
+ }, /*#__PURE__*/React.createElement(ChunkExtractor, {
1156
1248
  extractor: providers.loadable.extractor
1157
1249
  }, /*#__PURE__*/React.createElement(CookiesProvider, {
1158
1250
  cookies: providers.cookies
@@ -1161,16 +1253,20 @@ const ssrJsxProducer = (ReactApp, {
1161
1253
  }, /*#__PURE__*/React.createElement(HttpContext.Provider, {
1162
1254
  value: providers.httpContext
1163
1255
  }, /*#__PURE__*/React.createElement(StaticRouter, {
1164
- location: providers.router.url
1256
+ location: providers.router.url,
1257
+ future: {
1258
+ v7_startTransition: true,
1259
+ v7_relativeSplatPath: true
1260
+ }
1165
1261
  }, /*#__PURE__*/React.createElement(SSRContextProvider, {
1166
1262
  accessMethod: providers.ssrContext.accessMethod,
1167
1263
  request: providers.ssrContext.request,
1168
- response: providers.ssrContext.response,
1169
- ssrAssets: ssrAssets
1264
+ response: providers.ssrContext.response
1265
+ // ssrAssets={ssrAssets}
1170
1266
  }, /*#__PURE__*/React.createElement(ReactApp, {
1171
1267
  routes: props.routes,
1172
1268
  withEvents: props.withEvents
1173
- })))))));
1269
+ }))))))));
1174
1270
 
1175
1271
  // Wrap the JSX in a StyleSheetManager if a ServerStyleSheet is provided
1176
1272
  return !((_providers$styledComp = providers.styledComponents) !== null && _providers$styledComp !== void 0 && _providers$styledComp.sheet) ? jsx : providers.styledComponents.sheet.collectStyles(jsx);
@@ -1178,7 +1274,7 @@ const ssrJsxProducer = (ReactApp, {
1178
1274
 
1179
1275
  const webApp = (app, ReactApp, config) => {
1180
1276
  const {
1181
- stateType = 'immutable',
1277
+ stateType = 'js',
1182
1278
  routes,
1183
1279
  withReducers,
1184
1280
  withSagas,
@@ -1192,8 +1288,12 @@ const webApp = (app, ReactApp, config) => {
1192
1288
  disableSsrRedux,
1193
1289
  enableSsrCookies,
1194
1290
  handleResponses,
1195
- handleExceptions = true
1291
+ handleExceptions = true,
1292
+ i18n
1196
1293
  } = config;
1294
+
1295
+ // process locales in static routes for i18n
1296
+ const localeRoutes = createLocaleRoutes(routes);
1197
1297
  const staticRoutePath = config.staticRoutePath || staticFolderPath;
1198
1298
  let isRenderingJsxToString = config.renderToString || false;
1199
1299
  const bundleData = getBundleData(config, staticRoutePath);
@@ -1207,8 +1307,16 @@ const webApp = (app, ReactApp, config) => {
1207
1307
  if (handleExceptions !== false) unhandledExceptionHandler(handleExceptions); // Create `process.on` event handlers for unhandled exceptions (Node v15+)
1208
1308
 
1209
1309
  const versionInfo = getVersionInfo(staticFolderPath);
1210
- app.get('/*', cookiesMiddleware(), async (request, response) => {
1211
- const url = encodeURI(request.url);
1310
+ app.get('/{*splat}', cookiesMiddleware(), async (request, response) => {
1311
+ /*
1312
+ * Do not inject url directly into HTML as it can lead to XSS attacks
1313
+ * CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
1314
+ * CWE-96: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)
1315
+ * Removed URL encoding as it causes inconsistencies when routes contain encoded characters in SSR
1316
+ * e.g. /search?category=sport%20and%20wellbeing becomes /search?category=sport%2520and%2520wellbeing
1317
+ * // const url = encodeURI(request.url);
1318
+ */
1319
+ const url = request.url;
1212
1320
  const matchedStaticRoute = matchRoutes(routes.StaticRoutes, request.path);
1213
1321
  const isStaticRoute = matchedStaticRoute && matchedStaticRoute.length > 0;
1214
1322
  if (isStaticRoute) {
@@ -1248,25 +1356,22 @@ const webApp = (app, ReactApp, config) => {
1248
1356
  // In server-side blocks world, the hostname requested by the client resides in the x-orig-host header
1249
1357
  // Because of this, we prioritize x-orig-host when setting our hostname
1250
1358
  const hostname = request.headers['x-orig-host'] || request.hostname;
1251
- console.info(`Request for ${request.path} hostname: ${hostname} versionStatus: ${versionStatus}`);
1359
+ const subsitePath = getSubsitePath(request);
1360
+ const subsitePathScript = subsitePath ? `window.subsitePath = ${serialize(subsitePath)};` : '';
1361
+ console.info(`[webApp] "${request.method} ${request.path}" hostname: ${hostname} versionStatus: ${versionStatus}`);
1252
1362
  store.dispatch(setVersionStatus(versionStatus));
1253
1363
  store.dispatch(setVersion(versionInfo.commitRef, versionInfo.buildNo));
1254
1364
  const project = pickProject(hostname, request.query);
1255
1365
  const groups = allowedGroups && allowedGroups[project];
1256
1366
  store.dispatch(setCurrentProject(project, groups, hostname));
1367
+ if (i18n) {
1368
+ store.dispatch(actions.INIT_LOCALES({
1369
+ locales: {},
1370
+ routes: localeRoutes,
1371
+ ...i18n
1372
+ }));
1373
+ }
1257
1374
  const loadableExtractor = loadableChunkExtractors();
1258
-
1259
- // type ChunkExtractorManagerPropsForReact18 = ChunkExtractorManagerProps & {
1260
- // children?: React.ReactNode;
1261
- // };
1262
-
1263
- // // Recast ChunkExtractorManager to avoid TS error `Property 'children' does not exist on type...`
1264
- // const ChunkExtractor = ChunkExtractorManager as ClassType<
1265
- // ChunkExtractorManagerPropsForReact18,
1266
- // Component<ChunkExtractorManagerPropsForReact18>,
1267
- // ComponentClass<ChunkExtractorManagerPropsForReact18>
1268
- // >;
1269
-
1270
1375
  const ssrCookies = enableSsrCookies ?
1271
1376
  // these cookies are managed by the cookiesMiddleware and contain listeners
1272
1377
  // when cookies are read or written in ssr can be added to the `set-cookie` response header
@@ -1281,12 +1386,17 @@ const webApp = (app, ReactApp, config) => {
1281
1386
  // and read back any context props set by the ReactApp
1282
1387
  const context = {};
1283
1388
 
1389
+ // Per-request helmet context object — populated by HelmetProvider during renderToString
1390
+ // Using a fresh object per request ensures thread safety under concurrent SSR requests
1391
+ const helmetContext = {};
1392
+
1284
1393
  // Amalgamate all props for the various Providers we wrap the ReactApp with
1285
1394
  const jsxProviderProps = {
1286
1395
  loadable: {
1287
1396
  extractor: loadableExtractor.commonLoadableExtractor
1288
1397
  },
1289
1398
  cookies: ssrCookies,
1399
+ helmet: helmetContext,
1290
1400
  redux: store,
1291
1401
  httpContext: context,
1292
1402
  router: {
@@ -1316,13 +1426,10 @@ const webApp = (app, ReactApp, config) => {
1316
1426
  // Dynamic doesn't need sagas
1317
1427
  // or styles, or any split component bundles
1318
1428
  // nor are we streaming responses
1319
- const isDynamicHints = `<script ${attributes}>window.versionStatus = "${versionStatus}"; window.isDynamic = true;</script>`;
1429
+ const isDynamicHints = `<script ${attributes}>window.isDynamic = true; ${subsitePathScript}</script>`;
1320
1430
  const jsx = ssrJsxProducer(ReactApp, {
1321
1431
  providers: jsxProviderProps,
1322
- props: jsxReactAppProps,
1323
- ssrAssets: {
1324
- serializedState: isDynamicHints
1325
- }
1432
+ props: jsxReactAppProps
1326
1433
  });
1327
1434
  renderToString(jsx);
1328
1435
 
@@ -1381,40 +1488,16 @@ const webApp = (app, ReactApp, config) => {
1381
1488
  return true;
1382
1489
  }
1383
1490
  if (!disableSsrRedux) {
1384
- // window.versionStatus is not strictly required here and is added to support cases
1385
- // where a consumer may not be using the contensisVersionStatus in redux and calling
1386
- // the `getClientSideVersionStatus()` method directly
1387
- serialisedReduxData = `<script ${attributes}>window.versionStatus = "${versionStatus}"; window.REDUX_DATA = ${serialisedReduxData}</script>`;
1491
+ serialisedReduxData = `<script ${attributes}>${subsitePathScript} window.__USE_HYDRATE__ = true; window.REDUX_DATA = ${serialisedReduxData}</script>`;
1388
1492
  }
1389
1493
  }
1390
1494
 
1391
1495
  // Responses
1392
-
1393
- const helmet = Helmet.renderStatic();
1394
- Helmet.rewind();
1395
- const htmlAttributes = helmet.htmlAttributes.toString();
1396
- let title = helmet.title.toString();
1397
- const metadata = helmet.meta.toString().concat(helmet.base.toString()).concat(helmet.link.toString()).concat(helmet.script.toString()).concat(helmet.noscript.toString());
1398
1496
  addStandardHeaders(reduxState, response, packagejson, {
1399
1497
  allowedGroups,
1400
1498
  globalGroups
1401
1499
  });
1402
-
1403
- // After running rootSaga there should be an additional react-loadable
1404
- // code-split bundles for any page components as well as core app bundles
1405
- const bundleTags = getBundleTags(loadableExtractor, scripts, staticRoutePath);
1406
1500
  const sheet = new ServerStyleSheet();
1407
- // Produce the ssr jsx one time so we can get any style tags to pass back in
1408
- ssrJsxProducer(ReactApp, {
1409
- providers: {
1410
- ...jsxProviderProps,
1411
- styledComponents: {
1412
- sheet
1413
- }
1414
- },
1415
- props: jsxReactAppProps
1416
- });
1417
- let styleTags = sheet.getStyleTags();
1418
1501
  const styledJsx = ssrJsxProducer(ReactApp, {
1419
1502
  providers: {
1420
1503
  ...jsxProviderProps,
@@ -1422,14 +1505,31 @@ const webApp = (app, ReactApp, config) => {
1422
1505
  sheet
1423
1506
  }
1424
1507
  },
1425
- props: jsxReactAppProps,
1426
- ssrAssets: {
1427
- bundleTags,
1428
- htmlAttributes,
1429
- metadata,
1430
- title
1431
- }
1508
+ props: jsxReactAppProps
1432
1509
  });
1510
+
1511
+ // We have to call renderToString() in order for all components to have
1512
+ // had chance to set the helmet metadata
1513
+ const html = renderToString(styledJsx);
1514
+ // Helmet.renderStatic() has to be called synchronously immediately after calling renderToString()
1515
+ // as it is not thread-safe (or specifically scoped to only this request)
1516
+ // TODO: deprecate `react-helmet`
1517
+ const helmet = Helmet.renderStatic();
1518
+
1519
+ // helmetContext is populated synchronously by HelmetProvider during renderToString()
1520
+ // It is scoped per-request via the helmetContext object, making this thread-safe
1521
+ // under concurrent SSR requests (unlike the previous Helmet.renderStatic() global singleton)
1522
+ const {
1523
+ helmet: helmetAsync
1524
+ } = helmetContext;
1525
+
1526
+ // Because we have had to call renderToString() here to reliably gather all helmet metadata
1527
+ // We could potentially call sheet.getStyleTags() here too and avoid piping a react-rendered
1528
+ // stream to a second stream to inject styled-components CSS
1529
+
1530
+ const htmlAttributes = helmetAsync.htmlAttributes.toString() || helmet.htmlAttributes.toString();
1531
+ let title = helmet.title.toString().includes('><') ? helmetAsync.title.toString() : helmet.title.toString();
1532
+ const metadata = helmetAsync.meta.toString().concat(helmetAsync.base.toString()).concat(helmetAsync.priority.toString()).concat(helmetAsync.link.toString()).concat(helmetAsync.script.toString()).concat(helmetAsync.noscript.toString()).concat(helmet.meta.toString()).concat(helmet.base.toString()).concat(helmet.link.toString()).concat(helmet.script.toString()).concat(helmet.noscript.toString());
1433
1533
  try {
1434
1534
  /**
1435
1535
  * Loads all page assets into the provided templateHTML
@@ -1440,7 +1540,8 @@ const webApp = (app, ReactApp, config) => {
1440
1540
  * we render the page as STATIC or render nothing
1441
1541
  * if the context has requested a redirect
1442
1542
  * */
1443
- const getContextHtml = renderedJsx => {
1543
+ const getContextHtml = (isFinal = false, styleTags, renderedJsxMarkup) => {
1544
+ var _loadableExtractor$mo;
1444
1545
  if (context.url) {
1445
1546
  response.redirect(context.statusCode || 302, context.url);
1446
1547
  return '';
@@ -1454,13 +1555,19 @@ const webApp = (app, ReactApp, config) => {
1454
1555
 
1455
1556
  // Set response.status from React StaticRouter
1456
1557
  if (typeof context.statusCode === 'number') response.status(context.statusCode);
1558
+ const bundleTags = isFinal ? getBundleTags(loadableExtractor, scripts, staticRoutePath) : '';
1559
+
1560
+ // Getting style tags generated by "CSS Modules" because they will be
1561
+ // available to loadable stats if we have built parts of the app with CSS
1562
+ // plugins that are not within styled-components
1563
+ const styles = loadableExtractor === null || loadableExtractor === void 0 || (_loadableExtractor$mo = loadableExtractor.modern) === null || _loadableExtractor$mo === void 0 ? void 0 : _loadableExtractor$mo.getStyleTags();
1457
1564
  const html = replaceHtml({
1458
1565
  bundleTags,
1459
- html: renderedJsx,
1566
+ html: renderedJsxMarkup,
1460
1567
  htmlAttributes,
1461
1568
  metadata,
1462
1569
  state: serialisedReduxData,
1463
- styleTags,
1570
+ styleTags: `${styleTags || ''}${styles || ''}`,
1464
1571
  title,
1465
1572
  templateHTML,
1466
1573
  templateHTMLFragment,
@@ -1469,12 +1576,14 @@ const webApp = (app, ReactApp, config) => {
1469
1576
  return html;
1470
1577
  };
1471
1578
  if (isRenderingJsxToString) {
1472
- const html = renderToString(styledJsx);
1473
- styleTags = sheet.getStyleTags();
1474
- const responseHTML = getContextHtml(html);
1579
+ // We have already (begrudgingly) rendered the JSX to a string above
1580
+ // so we can get all of the Helmet metadata out from any rendered component
1581
+ // const html = renderToString(styledJsx);
1582
+ const styleTags = sheet.getStyleTags();
1583
+ const responseHTML = getContextHtml(true, styleTags, html);
1475
1584
  responseHandler(request, response, responseHTML);
1476
1585
  } else {
1477
- renderStream(getContextHtml, styledJsx, response, styledComponentsStream(sheet));
1586
+ renderStream(getContextHtml, styledJsx, request, response, styledComponentsStream(sheet));
1478
1587
  }
1479
1588
  } catch (err) {
1480
1589
  console.info(err.message);
@@ -1536,5 +1645,5 @@ var internalServer = {
1536
1645
  start
1537
1646
  };
1538
1647
 
1539
- export { internalServer as default, makeLinkDepthApi as linkDepthApi };
1648
+ export { subsiteDebugMiddleware as DO_NOT_COMMIT_subsiteDebugMiddleware, internalServer as default, makeLinkDepthApi as linkDepthApi };
1540
1649
  //# sourceMappingURL=contensis-react-base.js.map