@hubspot/cms-dev-server 0.7.8 → 0.8.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.
Binary file
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ function resolveIslandPlugin() {
39
39
  }
40
40
  };
41
41
  }
42
- var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
42
+ var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
43
43
  var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
44
44
  function clientIslandEntryPlugin() {
45
45
  return {
@@ -75,6 +75,8 @@ function clientIslandEntryPlugin() {
75
75
 
76
76
  // src/createViteDevServer.ts
77
77
  import mkcert from "vite-plugin-mkcert";
78
+ import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
79
+ import { default as Inspect } from "vite-plugin-inspect";
78
80
  async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], __jsRenderingGates) {
79
81
  const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
80
82
  `${proxyDomain}.localhost`,
@@ -104,16 +106,22 @@ Custom origin: ${process.env.VITE_ORIGIN}
104
106
  },
105
107
  resolve: {
106
108
  conditions: ["server"],
107
- dedupe: ["react", "react-dom", "@hubspot/cms-components"]
109
+ dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
108
110
  },
109
111
  optimizeDeps: {
110
112
  include: ["react", "react-dom", "react-dom/client"]
111
113
  },
112
114
  plugins: [
113
115
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
114
- react(),
116
+ react({
117
+ babel: {
118
+ plugins: ["babel-plugin-styled-components", "styled-jsx/babel"]
119
+ }
120
+ }),
115
121
  clientIslandEntryPlugin(),
116
- resolveIslandPlugin()
122
+ resolveIslandPlugin(),
123
+ viteCommonjs(),
124
+ Inspect()
117
125
  ],
118
126
  css: {
119
127
  postcss: webRoot
@@ -86,7 +86,9 @@ var serializeIslandDataToJSON = (tweakedIslandsArray, indent = 0) => {
86
86
  clientOnly,
87
87
  priority,
88
88
  url,
89
- sharedStateID
89
+ sharedStateID,
90
+ wrapperModuleId,
91
+ wrapperUrl
90
92
  }) => {
91
93
  const output = {
92
94
  id,
@@ -101,6 +103,12 @@ var serializeIslandDataToJSON = (tweakedIslandsArray, indent = 0) => {
101
103
  if (sharedStateID) {
102
104
  output.sharedStateID = sharedStateID;
103
105
  }
106
+ if (wrapperModuleId) {
107
+ output.wrapperModuleId = wrapperModuleId;
108
+ }
109
+ if (wrapperUrl) {
110
+ output.wrapperUrl = wrapperUrl;
111
+ }
104
112
  return output;
105
113
  }
106
114
  ),
@@ -138,9 +146,16 @@ function getIslandUrls(roots, viteDevServer) {
138
146
  if (!islandModule) {
139
147
  throw new Error(`Unknown island moduleId: ${island.moduleId}`);
140
148
  }
149
+ let wrapperModule;
150
+ if (island.wrapperModuleId) {
151
+ wrapperModule = viteDevServer.moduleGraph.getModuleById(
152
+ island.wrapperModuleId
153
+ );
154
+ }
141
155
  const tweakedIsland = {
142
156
  ...island,
143
- url: islandModule.url
157
+ url: islandModule.url,
158
+ wrapperUrl: wrapperModule ? wrapperModule.url : void 0
144
159
  };
145
160
  return tweakedIsland;
146
161
  });
@@ -216,7 +231,7 @@ function resolveIslandPlugin() {
216
231
  }
217
232
  };
218
233
  }
219
- var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
234
+ var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
220
235
  var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
221
236
  function clientIslandEntryPlugin() {
222
237
  return {
@@ -532,8 +547,14 @@ function renderFieldsToJson(fields) {
532
547
  outputCallback
533
548
  })
534
549
  );
550
+ if (!moduleJson) {
551
+ throw new Error("couldn't render module fields definition to fields.json");
552
+ }
535
553
  return moduleJson;
536
554
  }
555
+ function isStylesheetAsset(staticAsset) {
556
+ return staticAsset.type === "stylesheet";
557
+ }
537
558
  export {
538
559
  COMPONENT_EXTENSIONS,
539
560
  CSS_LANGS_RE,
@@ -559,6 +580,7 @@ export {
559
580
  getServerGlobalsToInject,
560
581
  hasComponentExtension,
561
582
  isStorybookStory,
583
+ isStylesheetAsset,
562
584
  isUngatedFor,
563
585
  namespaceModulePropsShape,
564
586
  removeComponentExtension,
@@ -25,7 +25,15 @@ var startHydratingIdleRoots = () => {
25
25
  for (const root of rootsToProcess) {
26
26
  if (root.hydrationStatus === "HYDRATION_WAITING" && hydrationTypesToAccept.has(root.hydrateOn)) {
27
27
  root.hydrationStatus = "HYDRATION_PREPARING";
28
- waitThenLoadAndHydrateIfNeeded(root, getLoadableModuleFor(root));
28
+ waitThenLoadAndHydrateIfNeeded(
29
+ root,
30
+ getLoadableModuleFor(root),
31
+ root.wrapperUrl ? getLoadableModuleFor({
32
+ url: root.wrapperUrl,
33
+ id: `${root.id}-wrapper`,
34
+ moduleName: `${root.moduleName}-wrapper`
35
+ }) : void 0
36
+ );
29
37
  }
30
38
  }
31
39
  };
@@ -56,7 +64,7 @@ function finishHydratingRootAndScheduleNext(rootAndExtraInfo) {
56
64
  }
57
65
  }
58
66
  function hydrateRoot(rootAndExtraInfo) {
59
- const { rootEl, root, IslandModule } = rootAndExtraInfo;
67
+ const { rootEl, root, IslandModule, WrapperModule } = rootAndExtraInfo;
60
68
  console.log("Hydrating root", root.id, root.hydrateOn);
61
69
  const postHydration = () => {
62
70
  finishHydratingRootAndScheduleNext(rootAndExtraInfo);
@@ -68,6 +76,7 @@ function hydrateRoot(rootAndExtraInfo) {
68
76
  islands: typedWindow.__islands,
69
77
  postHydration,
70
78
  island: root,
79
+ WrapperModule: WrapperModule ? WrapperModule.default : void 0,
71
80
  index: rootAndExtraInfo.islandScheduledIndex
72
81
  };
73
82
  const reactRoot = IslandModule.render(renderableIsland);
@@ -80,29 +89,47 @@ function pushToHydrationQueue(rootAndExtraInfo) {
80
89
  hydrateRoot(rootAndExtraInfo);
81
90
  }
82
91
  }
83
- function loadThenHydrate(root, LoadableIslandModule, rootEl, islandScheduledIndex) {
84
- LoadableIslandModule().then((IslandModule) => {
85
- pushToHydrationQueue({
86
- rootEl,
87
- root,
88
- IslandModule,
89
- islandScheduledIndex
90
- });
91
- }).catch((error) => {
92
+ function loadThenHydrate(root, LoadableIslandModule, LoadableWrapperModule, rootEl, islandScheduledIndex) {
93
+ Promise.all([
94
+ LoadableIslandModule(),
95
+ LoadableWrapperModule ? LoadableWrapperModule() : Promise.resolve()
96
+ ]).then(
97
+ ([IslandModule, WrapperModule]) => {
98
+ pushToHydrationQueue({
99
+ rootEl,
100
+ root,
101
+ IslandModule,
102
+ WrapperModule,
103
+ islandScheduledIndex
104
+ });
105
+ }
106
+ ).catch((error) => {
92
107
  console.error(`Failed to load module for island: ${root.id}`);
93
108
  console.error(error);
94
109
  });
95
110
  }
96
- function waitThenLoadAndHydrateIfNeeded(root, LoadableIslandModule) {
111
+ function waitThenLoadAndHydrateIfNeeded(root, LoadableIslandModule, LoadableWrapperModule) {
97
112
  const rootEl = document.getElementById(root.id);
98
113
  const islandScheduledIndex = scheduledHydrationIndexCtr;
99
114
  scheduledHydrationIndexCtr += 1;
100
115
  if (root.hydrateOn === "visible") {
101
116
  onVisible(rootEl, () => {
102
- loadThenHydrate(root, LoadableIslandModule, rootEl, islandScheduledIndex);
117
+ loadThenHydrate(
118
+ root,
119
+ LoadableIslandModule,
120
+ LoadableWrapperModule,
121
+ rootEl,
122
+ islandScheduledIndex
123
+ );
103
124
  });
104
125
  } else {
105
- loadThenHydrate(root, LoadableIslandModule, rootEl, islandScheduledIndex);
126
+ loadThenHydrate(
127
+ root,
128
+ LoadableIslandModule,
129
+ LoadableWrapperModule,
130
+ rootEl,
131
+ islandScheduledIndex
132
+ );
106
133
  }
107
134
  }
108
135
  function getLoadableModuleFor(root) {
@@ -134,7 +161,15 @@ function hydrateIslandRoots() {
134
161
  if (hydrationTypesToAccept.has(root.hydrateOn)) {
135
162
  encounteredAnyNonIdleIslands = true;
136
163
  root.hydrationStatus = "HYDRATION_PREPARING";
137
- waitThenLoadAndHydrateIfNeeded(root, getLoadableModuleFor(root));
164
+ waitThenLoadAndHydrateIfNeeded(
165
+ root,
166
+ getLoadableModuleFor(root),
167
+ root.wrapperUrl ? getLoadableModuleFor({
168
+ url: root.wrapperUrl,
169
+ id: `${root.id}-wrapper`,
170
+ moduleName: `${root.moduleName}-wrapper`
171
+ }) : void 0
172
+ );
138
173
  }
139
174
  }
140
175
  }
package/dist/run.js CHANGED
@@ -55,6 +55,11 @@ function fullOriginalUrlFromRequest(request2) {
55
55
  return `${request2.protocol}://${request2.get("host")}${request2.originalUrl}`;
56
56
  }
57
57
 
58
+ // src/lib/renderComponentWithCSS.ts
59
+ import {
60
+ renderToStaticMarkup as renderToStaticMarkup2
61
+ } from "react-dom/server";
62
+
58
63
  // src/lib/packagePath.ts
59
64
  import path from "path";
60
65
  import url from "url";
@@ -101,7 +106,9 @@ var serializeIslandDataToJSON = (tweakedIslandsArray, indent = 0) => {
101
106
  clientOnly,
102
107
  priority,
103
108
  url: url3,
104
- sharedStateID
109
+ sharedStateID,
110
+ wrapperModuleId,
111
+ wrapperUrl
105
112
  }) => {
106
113
  const output = {
107
114
  id,
@@ -116,6 +123,12 @@ var serializeIslandDataToJSON = (tweakedIslandsArray, indent = 0) => {
116
123
  if (sharedStateID) {
117
124
  output.sharedStateID = sharedStateID;
118
125
  }
126
+ if (wrapperModuleId) {
127
+ output.wrapperModuleId = wrapperModuleId;
128
+ }
129
+ if (wrapperUrl) {
130
+ output.wrapperUrl = wrapperUrl;
131
+ }
119
132
  return output;
120
133
  }
121
134
  ),
@@ -153,9 +166,16 @@ function getIslandUrls(roots, viteDevServer) {
153
166
  if (!islandModule) {
154
167
  throw new Error(`Unknown island moduleId: ${island.moduleId}`);
155
168
  }
169
+ let wrapperModule;
170
+ if (island.wrapperModuleId) {
171
+ wrapperModule = viteDevServer.moduleGraph.getModuleById(
172
+ island.wrapperModuleId
173
+ );
174
+ }
156
175
  const tweakedIsland = {
157
176
  ...island,
158
- url: islandModule.url
177
+ url: islandModule.url,
178
+ wrapperUrl: wrapperModule ? wrapperModule.url : void 0
159
179
  };
160
180
  return tweakedIsland;
161
181
  });
@@ -231,7 +251,7 @@ function resolveIslandPlugin() {
231
251
  }
232
252
  };
233
253
  }
234
- var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
254
+ var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
235
255
  var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
236
256
  function clientIslandEntryPlugin() {
237
257
  return {
@@ -507,6 +527,9 @@ function renderFieldsToJson(fields) {
507
527
  outputCallback
508
528
  })
509
529
  );
530
+ if (!moduleJson) {
531
+ throw new Error("couldn't render module fields definition to fields.json");
532
+ }
510
533
  return moduleJson;
511
534
  }
512
535
 
@@ -561,7 +584,10 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
561
584
  viteServer,
562
585
  componentPath
563
586
  );
564
- const { html, renderContext } = await renderComponentOnServer(
587
+ const {
588
+ html,
589
+ renderContext
590
+ } = await renderComponentOnServer(
565
591
  Component,
566
592
  props,
567
593
  pageUrl,
@@ -570,7 +596,16 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
570
596
  renderOptions
571
597
  );
572
598
  const cssNeeded = collectCssInDev(componentPathWithExtension, viteServer);
573
- return { html, cssNeeded, renderContext };
599
+ let inlineAssets = [];
600
+ if (renderContext.inlineAssets && Array.isArray(renderContext.inlineAssets)) {
601
+ inlineAssets = renderContext.inlineAssets.map(
602
+ ({ render: staticAssetRenderFunc, ...staticAsset }) => ({
603
+ ...staticAsset,
604
+ html: renderToStaticMarkup2(staticAssetRenderFunc())
605
+ })
606
+ );
607
+ }
608
+ return { html, inlineAssets, cssNeeded, renderContext };
574
609
  }
575
610
  var renderComponentWithCSS_default = renderComponentWithCSS;
576
611
 
@@ -782,7 +817,8 @@ var partialRouteHandler = async (request2, response) => {
782
817
  const {
783
818
  html: renderedHtml,
784
819
  cssNeeded,
785
- renderContext
820
+ renderContext,
821
+ inlineAssets
786
822
  } = await renderPartial_default(
787
823
  viteServer,
788
824
  partialPath,
@@ -802,7 +838,12 @@ var partialRouteHandler = async (request2, response) => {
802
838
  viteServer,
803
839
  jsRenderingGates
804
840
  );
805
- const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
841
+ const html = htmlShell.replace(
842
+ "<!--headend-->",
843
+ [cssNeeded, ...inlineAssets.map((inlineAsset) => inlineAsset.html)].join(
844
+ "\n"
845
+ )
846
+ ).replace(`<!--ssr-outlet-->`, renderedHtml);
806
847
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
807
848
  } catch (e) {
808
849
  console.error(e);
@@ -1085,7 +1126,8 @@ var moduleRouteHandler = async (request2, response) => {
1085
1126
  const {
1086
1127
  html: renderedHtml,
1087
1128
  cssNeeded,
1088
- renderContext
1129
+ renderContext,
1130
+ inlineAssets
1089
1131
  } = await renderModule_default(
1090
1132
  viteServer,
1091
1133
  modulePath,
@@ -1105,7 +1147,7 @@ var moduleRouteHandler = async (request2, response) => {
1105
1147
  viteServer,
1106
1148
  jsRenderingGates
1107
1149
  );
1108
- const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
1150
+ const html = htmlShell.replace("<!--headend-->", [cssNeeded, ...inlineAssets].join("\n")).replace(`<!--ssr-outlet-->`, renderedHtml);
1109
1151
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
1110
1152
  } catch (e) {
1111
1153
  console.error(e);
@@ -1328,7 +1370,8 @@ var fakeRenderJsComponent = (indexForThisRender) => {
1328
1370
  resolve3({
1329
1371
  html: fakeJsRenderedOutput,
1330
1372
  cssNeeded: "",
1331
- renderContext: createEmptyServerRenderContext()
1373
+ renderContext: createEmptyServerRenderContext(),
1374
+ inlineAssets: []
1332
1375
  });
1333
1376
  } catch (e) {
1334
1377
  console.log("Error with JS render...");
@@ -1631,7 +1674,7 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1631
1674
  projectComponentPath
1632
1675
  );
1633
1676
  renderPromisesByChunkIndex[indexForThisRender] = renderPromise.then((promiseResult) => {
1634
- let { html, cssNeeded, renderContext } = promiseResult;
1677
+ let { html, cssNeeded, inlineAssets, renderContext } = promiseResult;
1635
1678
  console.log(
1636
1679
  `Finished render of ${localRenderPlaceholder.path} (i = ${indexForThisRender})`
1637
1680
  );
@@ -1642,11 +1685,16 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1642
1685
  mergedPerRequestState,
1643
1686
  renderContext.perServerRequestData
1644
1687
  );
1688
+ let result = html;
1689
+ if (inlineAssets) {
1690
+ result = `${inlineAssets.map((inlineAsset) => inlineAsset.html).join("\n")}
1691
+ ${result}`;
1692
+ }
1645
1693
  if (cssNeeded) {
1646
- return `${cssNeeded}
1647
- ${html}`;
1694
+ result = `${cssNeeded}
1695
+ ${result}`;
1648
1696
  }
1649
- return html;
1697
+ return result;
1650
1698
  }).catch((e) => {
1651
1699
  numJsRenderFailures += 1;
1652
1700
  console.log(
@@ -2096,6 +2144,8 @@ async function startShadowDevServer(devServerPort, shadowPort, projectName, jsRe
2096
2144
  import { createServer as createViteServer } from "vite";
2097
2145
  import { default as react } from "@vitejs/plugin-react";
2098
2146
  import mkcert from "vite-plugin-mkcert";
2147
+ import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
2148
+ import { default as Inspect } from "vite-plugin-inspect";
2099
2149
  async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [], __jsRenderingGates) {
2100
2150
  const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
2101
2151
  `${proxyDomain}.localhost`,
@@ -2125,16 +2175,22 @@ Custom origin: ${process.env.VITE_ORIGIN}
2125
2175
  },
2126
2176
  resolve: {
2127
2177
  conditions: ["server"],
2128
- dedupe: ["react", "react-dom", "@hubspot/cms-components"]
2178
+ dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
2129
2179
  },
2130
2180
  optimizeDeps: {
2131
2181
  include: ["react", "react-dom", "react-dom/client"]
2132
2182
  },
2133
2183
  plugins: [
2134
2184
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
2135
- react(),
2185
+ react({
2186
+ babel: {
2187
+ plugins: ["babel-plugin-styled-components", "styled-jsx/babel"]
2188
+ }
2189
+ }),
2136
2190
  clientIslandEntryPlugin(),
2137
- resolveIslandPlugin()
2191
+ resolveIslandPlugin(),
2192
+ viteCommonjs(),
2193
+ Inspect()
2138
2194
  ],
2139
2195
  css: {
2140
2196
  postcss: webRoot2
@@ -1,6 +1,5 @@
1
1
  // src/storybook/moduleStory.tsx
2
- import React, { useEffect } from "react";
3
- import { renderToStaticMarkup as renderToStaticMarkup2 } from "react-dom/server";
2
+ import { useEffect } from "react";
4
3
 
5
4
  // ../cms-js-internal/dist/index.js
6
5
  import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
@@ -36,6 +35,9 @@ function renderFieldsToJson(fields) {
36
35
  outputCallback
37
36
  })
38
37
  );
38
+ if (!moduleJson) {
39
+ throw new Error("couldn't render module fields definition to fields.json");
40
+ }
39
41
  return moduleJson;
40
42
  }
41
43
 
@@ -125,21 +127,6 @@ function getNestedFieldObjectForArgs(_args) {
125
127
 
126
128
  // src/storybook/moduleStory.tsx
127
129
  import { jsx } from "react/jsx-runtime";
128
- function moduleFieldsToJson(fields) {
129
- let moduleJson;
130
- const outputCallback = (callbackJson) => {
131
- moduleJson = callbackJson;
132
- };
133
- renderToStaticMarkup2(
134
- React.cloneElement(fields, {
135
- outputCallback
136
- })
137
- );
138
- if (!moduleJson) {
139
- throw new Error("couldn't render module fields definition to fields.json");
140
- }
141
- return moduleJson;
142
- }
143
130
  function moduleArgs(argTypes) {
144
131
  const args = {};
145
132
  for (const argKey in argTypes) {
@@ -163,18 +150,18 @@ function moduleStory(ModuleComponent, fields, storyArgs) {
163
150
  args
164
151
  };
165
152
  }
166
- function moduleStoryWithIsland(fields, moduleName, storyArgs) {
153
+ function moduleStoryWithIsland(moduleName, fields, storyArgs) {
167
154
  if (typeof moduleName !== "string") {
168
155
  throw new Error(
169
- "moduleStoryWithIsland takes Fields JSX as the first argument, and the moduleName that matches the file or folder name for the module as a string for the second parameter"
156
+ "moduleStoryWithIsland takes a `moduleName` that matches the file or folder name for the module as a string for the first argument, and the module's Fields JSX as the second parameter"
170
157
  );
171
158
  }
172
- if (!moduleName) {
159
+ if (!fields) {
173
160
  throw new Error(
174
- "moduleStoryWithIsland requires a second moduleName parameter that matches the file or folder name for the module"
161
+ "moduleStoryWithIsland requires a second parameter of the module's fields configuration"
175
162
  );
176
163
  }
177
- const moduleJson = moduleFieldsToJson(fields);
164
+ const moduleJson = renderFieldsToJson(fields);
178
165
  const argTypes = getFieldsArgTypes(moduleJson);
179
166
  const args = { ...moduleArgs(argTypes), ...storyArgs };
180
167
  return {
@@ -199,7 +186,7 @@ function moduleStoryWithIsland(fields, moduleName, storyArgs) {
199
186
  iframeElement.setAttribute("id", "hs-module-iframe");
200
187
  iframeElement.setAttribute(
201
188
  "style",
202
- `border: none;width: 100%;height: 100%;overflow: auto;`
189
+ `border: none;width: 100%;height: 100%;overflow: auto;position: absolute;left: 0;top: 0;`
203
190
  );
204
191
  document.querySelector("#storybook-root").appendChild(iframeElement);
205
192
  return () => {
@@ -211,7 +198,6 @@ function moduleStoryWithIsland(fields, moduleName, storyArgs) {
211
198
  };
212
199
  }
213
200
  export {
214
- moduleFieldsToJson,
215
201
  moduleStory,
216
202
  moduleStoryWithIsland
217
203
  };
@@ -35,6 +35,7 @@ __export(dist_exports, {
35
35
  getServerGlobalsToInject: () => getServerGlobalsToInject,
36
36
  hasComponentExtension: () => hasComponentExtension,
37
37
  isStorybookStory: () => isStorybookStory,
38
+ isStylesheetAsset: () => isStylesheetAsset,
38
39
  isUngatedFor: () => isUngatedFor,
39
40
  namespaceModulePropsShape: () => namespaceModulePropsShape,
40
41
  removeComponentExtension: () => removeComponentExtension,
@@ -89,9 +90,16 @@ function getIslandUrls(roots, viteDevServer) {
89
90
  if (!islandModule) {
90
91
  throw new Error(`Unknown island moduleId: ${island.moduleId}`);
91
92
  }
93
+ let wrapperModule;
94
+ if (island.wrapperModuleId) {
95
+ wrapperModule = viteDevServer.moduleGraph.getModuleById(
96
+ island.wrapperModuleId
97
+ );
98
+ }
92
99
  const tweakedIsland = {
93
100
  ...island,
94
- url: islandModule.url
101
+ url: islandModule.url,
102
+ wrapperUrl: wrapperModule ? wrapperModule.url : void 0
95
103
  };
96
104
  return tweakedIsland;
97
105
  });
@@ -332,8 +340,14 @@ function renderFieldsToJson(fields) {
332
340
  outputCallback
333
341
  })
334
342
  );
343
+ if (!moduleJson) {
344
+ throw new Error("couldn't render module fields definition to fields.json");
345
+ }
335
346
  return moduleJson;
336
347
  }
348
+ function isStylesheetAsset(staticAsset) {
349
+ return staticAsset.type === "stylesheet";
350
+ }
337
351
  var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, GATES, ENABLED_FEATURES_GATE_MAP, BUILD_INFO_PATH, findAllComponentsIn;
338
352
  var init_dist = __esm({
339
353
  "../cms-js-internal/dist/index.js"() {
@@ -392,7 +406,9 @@ var init_dist = __esm({
392
406
  clientOnly,
393
407
  priority,
394
408
  url,
395
- sharedStateID
409
+ sharedStateID,
410
+ wrapperModuleId,
411
+ wrapperUrl
396
412
  }) => {
397
413
  const output = {
398
414
  id,
@@ -407,6 +423,12 @@ var init_dist = __esm({
407
423
  if (sharedStateID) {
408
424
  output.sharedStateID = sharedStateID;
409
425
  }
426
+ if (wrapperModuleId) {
427
+ output.wrapperModuleId = wrapperModuleId;
428
+ }
429
+ if (wrapperUrl) {
430
+ output.wrapperUrl = wrapperUrl;
431
+ }
410
432
  return output;
411
433
  }
412
434
  ),
@@ -451,7 +473,7 @@ ${indentString}`);
451
473
  indent
452
474
  )}`;
453
475
  };
454
- clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n <Component islandId={island.id} {...island.props} />\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
476
+ clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
455
477
  virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
456
478
  jsx2 = jsxRuntime.jsx;
457
479
  promiseForNewWritableStream = () => {
@@ -628,7 +650,8 @@ var main_default = {
628
650
  ]
629
651
  },
630
652
  optimizeDeps: {
631
- include: ["react", "react-dom", "react-dom/client"]
653
+ include: ["react", "react-dom", "react-dom/client"],
654
+ exclude: ["fsevents"]
632
655
  },
633
656
  css: {
634
657
  postcss: webRoot
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.7.8",
3
+ "version": "0.8.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -25,7 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@hubspot/cli-lib": "^3.0.12",
28
- "@hubspot/cms-components": "^0.7.8",
28
+ "@hubspot/cms-components": "^0.8.0",
29
+ "@originjs/vite-plugin-commonjs": "^1.0.3",
29
30
  "@storybook/addon-actions": "7.0.7",
30
31
  "@storybook/addon-essentials": "7.0.7",
31
32
  "@storybook/addon-interactions": "7.0.7",
@@ -34,8 +35,9 @@
34
35
  "@storybook/react": "7.0.7",
35
36
  "@storybook/react-vite": "7.0.7",
36
37
  "@storybook/testing-library": "^0.0.13",
37
- "@vitejs/plugin-react": "^3.0.0",
38
+ "@vitejs/plugin-react": "^4.0.0",
38
39
  "ansi-to-html": "0.7.x",
40
+ "babel-plugin-styled-components": "^2.1.4",
39
41
  "cors": "^2.8.5",
40
42
  "debug": "^4.3.4",
41
43
  "express": "^4.17.3",
@@ -44,6 +46,7 @@
44
46
  "react": "^18.1.0",
45
47
  "react-dom": "^18.1.0",
46
48
  "request": "^2.88.2",
49
+ "styled-jsx": "5.1.2",
47
50
  "typescript": "~4.7.0",
48
51
  "vite": "4.3.4",
49
52
  "vite-plugin-inspect": "^0.4.3",
@@ -97,5 +100,5 @@
97
100
  "publishConfig": {
98
101
  "access": "public"
99
102
  },
100
- "gitHead": "550fdb98095e7f74b3fedd9cc72b8ac3b90f4acc"
103
+ "gitHead": "554152ecb8091d5484f085c82a2ccecf6ce467d4"
101
104
  }
@@ -0,0 +1,2 @@
1
+ import { Alias } from 'vite';
2
+ export default function generateBpmAliases(webRoot: string): Alias[];