@hubspot/cms-dev-server 0.7.9 → 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.
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 {
@@ -537,6 +552,9 @@ function renderFieldsToJson(fields) {
537
552
  }
538
553
  return moduleJson;
539
554
  }
555
+ function isStylesheetAsset(staticAsset) {
556
+ return staticAsset.type === "stylesheet";
557
+ }
540
558
  export {
541
559
  COMPONENT_EXTENSIONS,
542
560
  CSS_LANGS_RE,
@@ -562,6 +580,7 @@ export {
562
580
  getServerGlobalsToInject,
563
581
  hasComponentExtension,
564
582
  isStorybookStory,
583
+ isStylesheetAsset,
565
584
  isUngatedFor,
566
585
  namespaceModulePropsShape,
567
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 {
@@ -564,7 +584,10 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
564
584
  viteServer,
565
585
  componentPath
566
586
  );
567
- const { html, renderContext } = await renderComponentOnServer(
587
+ const {
588
+ html,
589
+ renderContext
590
+ } = await renderComponentOnServer(
568
591
  Component,
569
592
  props,
570
593
  pageUrl,
@@ -573,7 +596,16 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
573
596
  renderOptions
574
597
  );
575
598
  const cssNeeded = collectCssInDev(componentPathWithExtension, viteServer);
576
- 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 };
577
609
  }
578
610
  var renderComponentWithCSS_default = renderComponentWithCSS;
579
611
 
@@ -785,7 +817,8 @@ var partialRouteHandler = async (request2, response) => {
785
817
  const {
786
818
  html: renderedHtml,
787
819
  cssNeeded,
788
- renderContext
820
+ renderContext,
821
+ inlineAssets
789
822
  } = await renderPartial_default(
790
823
  viteServer,
791
824
  partialPath,
@@ -805,7 +838,12 @@ var partialRouteHandler = async (request2, response) => {
805
838
  viteServer,
806
839
  jsRenderingGates
807
840
  );
808
- 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);
809
847
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
810
848
  } catch (e) {
811
849
  console.error(e);
@@ -1088,7 +1126,8 @@ var moduleRouteHandler = async (request2, response) => {
1088
1126
  const {
1089
1127
  html: renderedHtml,
1090
1128
  cssNeeded,
1091
- renderContext
1129
+ renderContext,
1130
+ inlineAssets
1092
1131
  } = await renderModule_default(
1093
1132
  viteServer,
1094
1133
  modulePath,
@@ -1108,7 +1147,7 @@ var moduleRouteHandler = async (request2, response) => {
1108
1147
  viteServer,
1109
1148
  jsRenderingGates
1110
1149
  );
1111
- const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
1150
+ const html = htmlShell.replace("<!--headend-->", [cssNeeded, ...inlineAssets].join("\n")).replace(`<!--ssr-outlet-->`, renderedHtml);
1112
1151
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
1113
1152
  } catch (e) {
1114
1153
  console.error(e);
@@ -1331,7 +1370,8 @@ var fakeRenderJsComponent = (indexForThisRender) => {
1331
1370
  resolve3({
1332
1371
  html: fakeJsRenderedOutput,
1333
1372
  cssNeeded: "",
1334
- renderContext: createEmptyServerRenderContext()
1373
+ renderContext: createEmptyServerRenderContext(),
1374
+ inlineAssets: []
1335
1375
  });
1336
1376
  } catch (e) {
1337
1377
  console.log("Error with JS render...");
@@ -1634,7 +1674,7 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1634
1674
  projectComponentPath
1635
1675
  );
1636
1676
  renderPromisesByChunkIndex[indexForThisRender] = renderPromise.then((promiseResult) => {
1637
- let { html, cssNeeded, renderContext } = promiseResult;
1677
+ let { html, cssNeeded, inlineAssets, renderContext } = promiseResult;
1638
1678
  console.log(
1639
1679
  `Finished render of ${localRenderPlaceholder.path} (i = ${indexForThisRender})`
1640
1680
  );
@@ -1645,11 +1685,16 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
1645
1685
  mergedPerRequestState,
1646
1686
  renderContext.perServerRequestData
1647
1687
  );
1688
+ let result = html;
1689
+ if (inlineAssets) {
1690
+ result = `${inlineAssets.map((inlineAsset) => inlineAsset.html).join("\n")}
1691
+ ${result}`;
1692
+ }
1648
1693
  if (cssNeeded) {
1649
- return `${cssNeeded}
1650
- ${html}`;
1694
+ result = `${cssNeeded}
1695
+ ${result}`;
1651
1696
  }
1652
- return html;
1697
+ return result;
1653
1698
  }).catch((e) => {
1654
1699
  numJsRenderFailures += 1;
1655
1700
  console.log(
@@ -2099,6 +2144,8 @@ async function startShadowDevServer(devServerPort, shadowPort, projectName, jsRe
2099
2144
  import { createServer as createViteServer } from "vite";
2100
2145
  import { default as react } from "@vitejs/plugin-react";
2101
2146
  import mkcert from "vite-plugin-mkcert";
2147
+ import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
2148
+ import { default as Inspect } from "vite-plugin-inspect";
2102
2149
  async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [], __jsRenderingGates) {
2103
2150
  const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
2104
2151
  `${proxyDomain}.localhost`,
@@ -2128,16 +2175,22 @@ Custom origin: ${process.env.VITE_ORIGIN}
2128
2175
  },
2129
2176
  resolve: {
2130
2177
  conditions: ["server"],
2131
- dedupe: ["react", "react-dom", "@hubspot/cms-components"]
2178
+ dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
2132
2179
  },
2133
2180
  optimizeDeps: {
2134
2181
  include: ["react", "react-dom", "react-dom/client"]
2135
2182
  },
2136
2183
  plugins: [
2137
2184
  sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
2138
- react(),
2185
+ react({
2186
+ babel: {
2187
+ plugins: ["babel-plugin-styled-components", "styled-jsx/babel"]
2188
+ }
2189
+ }),
2139
2190
  clientIslandEntryPlugin(),
2140
- resolveIslandPlugin()
2191
+ resolveIslandPlugin(),
2192
+ viteCommonjs(),
2193
+ Inspect()
2141
2194
  ],
2142
2195
  css: {
2143
2196
  postcss: webRoot2
@@ -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
  });
@@ -337,6 +345,9 @@ function renderFieldsToJson(fields) {
337
345
  }
338
346
  return moduleJson;
339
347
  }
348
+ function isStylesheetAsset(staticAsset) {
349
+ return staticAsset.type === "stylesheet";
350
+ }
340
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;
341
352
  var init_dist = __esm({
342
353
  "../cms-js-internal/dist/index.js"() {
@@ -395,7 +406,9 @@ var init_dist = __esm({
395
406
  clientOnly,
396
407
  priority,
397
408
  url,
398
- sharedStateID
409
+ sharedStateID,
410
+ wrapperModuleId,
411
+ wrapperUrl
399
412
  }) => {
400
413
  const output = {
401
414
  id,
@@ -410,6 +423,12 @@ var init_dist = __esm({
410
423
  if (sharedStateID) {
411
424
  output.sharedStateID = sharedStateID;
412
425
  }
426
+ if (wrapperModuleId) {
427
+ output.wrapperModuleId = wrapperModuleId;
428
+ }
429
+ if (wrapperUrl) {
430
+ output.wrapperUrl = wrapperUrl;
431
+ }
413
432
  return output;
414
433
  }
415
434
  ),
@@ -454,7 +473,7 @@ ${indentString}`);
454
473
  indent
455
474
  )}`;
456
475
  };
457
- 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";
458
477
  virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
459
478
  jsx2 = jsxRuntime.jsx;
460
479
  promiseForNewWritableStream = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.7.9",
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.9",
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": "fe80fcc6421a19c814bfcb1652d02d7c16c625b6"
103
+ "gitHead": "554152ecb8091d5484f085c82a2ccecf6ce467d4"
101
104
  }