@hubspot/cms-dev-server 0.7.9 → 0.8.1
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 +16 -5
- package/dist/internalSsr.js +26 -4
- package/dist/island-runtime.js +50 -15
- package/dist/run.js +74 -18
- package/dist/storybook-main/main.js +26 -4
- package/package.json +7 -4
- package/dist/fsevents-72LCIACT.node +0 -0
- package/types/generateBpmAliases.d.ts +0 -2
- package/types/noNodeBuiltinsPlugin.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { default as react } from "@vitejs/plugin-react";
|
|
|
6
6
|
import path, { basename } from "path";
|
|
7
7
|
var viteRoot;
|
|
8
8
|
var viteCommand;
|
|
9
|
-
function resolveIslandPlugin() {
|
|
9
|
+
function resolveIslandPlugin(islandsSet) {
|
|
10
10
|
return {
|
|
11
11
|
enforce: "pre",
|
|
12
12
|
name: "resolve-islands",
|
|
@@ -25,6 +25,9 @@ function resolveIslandPlugin() {
|
|
|
25
25
|
);
|
|
26
26
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
27
27
|
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
28
|
+
if (islandsSet) {
|
|
29
|
+
islandsSet.add(moduleId);
|
|
30
|
+
}
|
|
28
31
|
return `
|
|
29
32
|
const moduleId = '${moduleId}';
|
|
30
33
|
|
|
@@ -39,7 +42,7 @@ function resolveIslandPlugin() {
|
|
|
39
42
|
}
|
|
40
43
|
};
|
|
41
44
|
}
|
|
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
|
|
45
|
+
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
46
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
44
47
|
function clientIslandEntryPlugin() {
|
|
45
48
|
return {
|
|
@@ -75,6 +78,8 @@ function clientIslandEntryPlugin() {
|
|
|
75
78
|
|
|
76
79
|
// src/createViteDevServer.ts
|
|
77
80
|
import mkcert from "vite-plugin-mkcert";
|
|
81
|
+
import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
|
|
82
|
+
import { default as Inspect } from "vite-plugin-inspect";
|
|
78
83
|
async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], __jsRenderingGates) {
|
|
79
84
|
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
80
85
|
`${proxyDomain}.localhost`,
|
|
@@ -104,16 +109,22 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
104
109
|
},
|
|
105
110
|
resolve: {
|
|
106
111
|
conditions: ["server"],
|
|
107
|
-
dedupe: ["react", "react-dom", "@hubspot/cms-components"]
|
|
112
|
+
dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
|
|
108
113
|
},
|
|
109
114
|
optimizeDeps: {
|
|
110
115
|
include: ["react", "react-dom", "react-dom/client"]
|
|
111
116
|
},
|
|
112
117
|
plugins: [
|
|
113
118
|
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
114
|
-
react(
|
|
119
|
+
react({
|
|
120
|
+
babel: {
|
|
121
|
+
plugins: ["babel-plugin-styled-components", "styled-jsx/babel"]
|
|
122
|
+
}
|
|
123
|
+
}),
|
|
115
124
|
clientIslandEntryPlugin(),
|
|
116
|
-
resolveIslandPlugin()
|
|
125
|
+
resolveIslandPlugin(),
|
|
126
|
+
viteCommonjs(),
|
|
127
|
+
Inspect()
|
|
117
128
|
],
|
|
118
129
|
css: {
|
|
119
130
|
postcss: webRoot
|
package/dist/internalSsr.js
CHANGED
|
@@ -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
|
});
|
|
@@ -183,7 +198,7 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
183
198
|
};
|
|
184
199
|
var viteRoot;
|
|
185
200
|
var viteCommand;
|
|
186
|
-
function resolveIslandPlugin() {
|
|
201
|
+
function resolveIslandPlugin(islandsSet) {
|
|
187
202
|
return {
|
|
188
203
|
enforce: "pre",
|
|
189
204
|
name: "resolve-islands",
|
|
@@ -202,6 +217,9 @@ function resolveIslandPlugin() {
|
|
|
202
217
|
);
|
|
203
218
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
204
219
|
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
220
|
+
if (islandsSet) {
|
|
221
|
+
islandsSet.add(moduleId);
|
|
222
|
+
}
|
|
205
223
|
return `
|
|
206
224
|
const moduleId = '${moduleId}';
|
|
207
225
|
|
|
@@ -216,7 +234,7 @@ function resolveIslandPlugin() {
|
|
|
216
234
|
}
|
|
217
235
|
};
|
|
218
236
|
}
|
|
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
|
|
237
|
+
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
238
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
221
239
|
function clientIslandEntryPlugin() {
|
|
222
240
|
return {
|
|
@@ -537,6 +555,9 @@ function renderFieldsToJson(fields) {
|
|
|
537
555
|
}
|
|
538
556
|
return moduleJson;
|
|
539
557
|
}
|
|
558
|
+
function isStylesheetAsset(staticAsset) {
|
|
559
|
+
return staticAsset.type === "stylesheet";
|
|
560
|
+
}
|
|
540
561
|
export {
|
|
541
562
|
COMPONENT_EXTENSIONS,
|
|
542
563
|
CSS_LANGS_RE,
|
|
@@ -562,6 +583,7 @@ export {
|
|
|
562
583
|
getServerGlobalsToInject,
|
|
563
584
|
hasComponentExtension,
|
|
564
585
|
isStorybookStory,
|
|
586
|
+
isStylesheetAsset,
|
|
565
587
|
isUngatedFor,
|
|
566
588
|
namespaceModulePropsShape,
|
|
567
589
|
removeComponentExtension,
|
package/dist/island-runtime.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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(
|
|
117
|
+
loadThenHydrate(
|
|
118
|
+
root,
|
|
119
|
+
LoadableIslandModule,
|
|
120
|
+
LoadableWrapperModule,
|
|
121
|
+
rootEl,
|
|
122
|
+
islandScheduledIndex
|
|
123
|
+
);
|
|
103
124
|
});
|
|
104
125
|
} else {
|
|
105
|
-
loadThenHydrate(
|
|
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(
|
|
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
|
});
|
|
@@ -198,7 +218,7 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
198
218
|
};
|
|
199
219
|
var viteRoot;
|
|
200
220
|
var viteCommand;
|
|
201
|
-
function resolveIslandPlugin() {
|
|
221
|
+
function resolveIslandPlugin(islandsSet) {
|
|
202
222
|
return {
|
|
203
223
|
enforce: "pre",
|
|
204
224
|
name: "resolve-islands",
|
|
@@ -217,6 +237,9 @@ function resolveIslandPlugin() {
|
|
|
217
237
|
);
|
|
218
238
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
219
239
|
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
240
|
+
if (islandsSet) {
|
|
241
|
+
islandsSet.add(moduleId);
|
|
242
|
+
}
|
|
220
243
|
return `
|
|
221
244
|
const moduleId = '${moduleId}';
|
|
222
245
|
|
|
@@ -231,7 +254,7 @@ function resolveIslandPlugin() {
|
|
|
231
254
|
}
|
|
232
255
|
};
|
|
233
256
|
}
|
|
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
|
|
257
|
+
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
258
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
236
259
|
function clientIslandEntryPlugin() {
|
|
237
260
|
return {
|
|
@@ -564,7 +587,10 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
|
|
|
564
587
|
viteServer,
|
|
565
588
|
componentPath
|
|
566
589
|
);
|
|
567
|
-
const {
|
|
590
|
+
const {
|
|
591
|
+
html,
|
|
592
|
+
renderContext
|
|
593
|
+
} = await renderComponentOnServer(
|
|
568
594
|
Component,
|
|
569
595
|
props,
|
|
570
596
|
pageUrl,
|
|
@@ -573,7 +599,16 @@ async function renderComponentWithCSS(viteServer, componentPath, Component, prop
|
|
|
573
599
|
renderOptions
|
|
574
600
|
);
|
|
575
601
|
const cssNeeded = collectCssInDev(componentPathWithExtension, viteServer);
|
|
576
|
-
|
|
602
|
+
let inlineAssets = [];
|
|
603
|
+
if (renderContext.inlineAssets && Array.isArray(renderContext.inlineAssets)) {
|
|
604
|
+
inlineAssets = renderContext.inlineAssets.map(
|
|
605
|
+
({ render: staticAssetRenderFunc, ...staticAsset }) => ({
|
|
606
|
+
...staticAsset,
|
|
607
|
+
html: renderToStaticMarkup2(staticAssetRenderFunc())
|
|
608
|
+
})
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
return { html, inlineAssets, cssNeeded, renderContext };
|
|
577
612
|
}
|
|
578
613
|
var renderComponentWithCSS_default = renderComponentWithCSS;
|
|
579
614
|
|
|
@@ -785,7 +820,8 @@ var partialRouteHandler = async (request2, response) => {
|
|
|
785
820
|
const {
|
|
786
821
|
html: renderedHtml,
|
|
787
822
|
cssNeeded,
|
|
788
|
-
renderContext
|
|
823
|
+
renderContext,
|
|
824
|
+
inlineAssets
|
|
789
825
|
} = await renderPartial_default(
|
|
790
826
|
viteServer,
|
|
791
827
|
partialPath,
|
|
@@ -805,7 +841,12 @@ var partialRouteHandler = async (request2, response) => {
|
|
|
805
841
|
viteServer,
|
|
806
842
|
jsRenderingGates
|
|
807
843
|
);
|
|
808
|
-
const html = htmlShell.replace(
|
|
844
|
+
const html = htmlShell.replace(
|
|
845
|
+
"<!--headend-->",
|
|
846
|
+
[cssNeeded, ...inlineAssets.map((inlineAsset) => inlineAsset.html)].join(
|
|
847
|
+
"\n"
|
|
848
|
+
)
|
|
849
|
+
).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
809
850
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
810
851
|
} catch (e) {
|
|
811
852
|
console.error(e);
|
|
@@ -1088,7 +1129,8 @@ var moduleRouteHandler = async (request2, response) => {
|
|
|
1088
1129
|
const {
|
|
1089
1130
|
html: renderedHtml,
|
|
1090
1131
|
cssNeeded,
|
|
1091
|
-
renderContext
|
|
1132
|
+
renderContext,
|
|
1133
|
+
inlineAssets
|
|
1092
1134
|
} = await renderModule_default(
|
|
1093
1135
|
viteServer,
|
|
1094
1136
|
modulePath,
|
|
@@ -1108,7 +1150,7 @@ var moduleRouteHandler = async (request2, response) => {
|
|
|
1108
1150
|
viteServer,
|
|
1109
1151
|
jsRenderingGates
|
|
1110
1152
|
);
|
|
1111
|
-
const html = htmlShell.replace("<!--headend-->", cssNeeded).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
1153
|
+
const html = htmlShell.replace("<!--headend-->", [cssNeeded, ...inlineAssets].join("\n")).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
1112
1154
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
1113
1155
|
} catch (e) {
|
|
1114
1156
|
console.error(e);
|
|
@@ -1331,7 +1373,8 @@ var fakeRenderJsComponent = (indexForThisRender) => {
|
|
|
1331
1373
|
resolve3({
|
|
1332
1374
|
html: fakeJsRenderedOutput,
|
|
1333
1375
|
cssNeeded: "",
|
|
1334
|
-
renderContext: createEmptyServerRenderContext()
|
|
1376
|
+
renderContext: createEmptyServerRenderContext(),
|
|
1377
|
+
inlineAssets: []
|
|
1335
1378
|
});
|
|
1336
1379
|
} catch (e) {
|
|
1337
1380
|
console.log("Error with JS render...");
|
|
@@ -1634,7 +1677,7 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
|
|
|
1634
1677
|
projectComponentPath
|
|
1635
1678
|
);
|
|
1636
1679
|
renderPromisesByChunkIndex[indexForThisRender] = renderPromise.then((promiseResult) => {
|
|
1637
|
-
let { html, cssNeeded, renderContext } = promiseResult;
|
|
1680
|
+
let { html, cssNeeded, inlineAssets, renderContext } = promiseResult;
|
|
1638
1681
|
console.log(
|
|
1639
1682
|
`Finished render of ${localRenderPlaceholder.path} (i = ${indexForThisRender})`
|
|
1640
1683
|
);
|
|
@@ -1645,11 +1688,16 @@ async function proxySpecificPage(response, portalId, hublet, contentId, webRoot2
|
|
|
1645
1688
|
mergedPerRequestState,
|
|
1646
1689
|
renderContext.perServerRequestData
|
|
1647
1690
|
);
|
|
1691
|
+
let result = html;
|
|
1692
|
+
if (inlineAssets) {
|
|
1693
|
+
result = `${inlineAssets.map((inlineAsset) => inlineAsset.html).join("\n")}
|
|
1694
|
+
${result}`;
|
|
1695
|
+
}
|
|
1648
1696
|
if (cssNeeded) {
|
|
1649
|
-
|
|
1650
|
-
${
|
|
1697
|
+
result = `${cssNeeded}
|
|
1698
|
+
${result}`;
|
|
1651
1699
|
}
|
|
1652
|
-
return
|
|
1700
|
+
return result;
|
|
1653
1701
|
}).catch((e) => {
|
|
1654
1702
|
numJsRenderFailures += 1;
|
|
1655
1703
|
console.log(
|
|
@@ -2099,6 +2147,8 @@ async function startShadowDevServer(devServerPort, shadowPort, projectName, jsRe
|
|
|
2099
2147
|
import { createServer as createViteServer } from "vite";
|
|
2100
2148
|
import { default as react } from "@vitejs/plugin-react";
|
|
2101
2149
|
import mkcert from "vite-plugin-mkcert";
|
|
2150
|
+
import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
|
|
2151
|
+
import { default as Inspect } from "vite-plugin-inspect";
|
|
2102
2152
|
async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [], __jsRenderingGates) {
|
|
2103
2153
|
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
2104
2154
|
`${proxyDomain}.localhost`,
|
|
@@ -2128,16 +2178,22 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
2128
2178
|
},
|
|
2129
2179
|
resolve: {
|
|
2130
2180
|
conditions: ["server"],
|
|
2131
|
-
dedupe: ["react", "react-dom", "@hubspot/cms-components"]
|
|
2181
|
+
dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
|
|
2132
2182
|
},
|
|
2133
2183
|
optimizeDeps: {
|
|
2134
2184
|
include: ["react", "react-dom", "react-dom/client"]
|
|
2135
2185
|
},
|
|
2136
2186
|
plugins: [
|
|
2137
2187
|
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
2138
|
-
react(
|
|
2188
|
+
react({
|
|
2189
|
+
babel: {
|
|
2190
|
+
plugins: ["babel-plugin-styled-components", "styled-jsx/babel"]
|
|
2191
|
+
}
|
|
2192
|
+
}),
|
|
2139
2193
|
clientIslandEntryPlugin(),
|
|
2140
|
-
resolveIslandPlugin()
|
|
2194
|
+
resolveIslandPlugin(),
|
|
2195
|
+
viteCommonjs(),
|
|
2196
|
+
Inspect()
|
|
2141
2197
|
],
|
|
2142
2198
|
css: {
|
|
2143
2199
|
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
|
});
|
|
@@ -117,7 +125,7 @@ function getPerServerRequestUrls(perServerRequestData, viteDevServer) {
|
|
|
117
125
|
});
|
|
118
126
|
return perServerRequestDataWithUrls;
|
|
119
127
|
}
|
|
120
|
-
function resolveIslandPlugin() {
|
|
128
|
+
function resolveIslandPlugin(islandsSet) {
|
|
121
129
|
return {
|
|
122
130
|
enforce: "pre",
|
|
123
131
|
name: "resolve-islands",
|
|
@@ -136,6 +144,9 @@ function resolveIslandPlugin() {
|
|
|
136
144
|
);
|
|
137
145
|
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
138
146
|
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
147
|
+
if (islandsSet) {
|
|
148
|
+
islandsSet.add(moduleId);
|
|
149
|
+
}
|
|
139
150
|
return `
|
|
140
151
|
const moduleId = '${moduleId}';
|
|
141
152
|
|
|
@@ -337,6 +348,9 @@ function renderFieldsToJson(fields) {
|
|
|
337
348
|
}
|
|
338
349
|
return moduleJson;
|
|
339
350
|
}
|
|
351
|
+
function isStylesheetAsset(staticAsset) {
|
|
352
|
+
return staticAsset.type === "stylesheet";
|
|
353
|
+
}
|
|
340
354
|
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
355
|
var init_dist = __esm({
|
|
342
356
|
"../cms-js-internal/dist/index.js"() {
|
|
@@ -395,7 +409,9 @@ var init_dist = __esm({
|
|
|
395
409
|
clientOnly,
|
|
396
410
|
priority,
|
|
397
411
|
url,
|
|
398
|
-
sharedStateID
|
|
412
|
+
sharedStateID,
|
|
413
|
+
wrapperModuleId,
|
|
414
|
+
wrapperUrl
|
|
399
415
|
}) => {
|
|
400
416
|
const output = {
|
|
401
417
|
id,
|
|
@@ -410,6 +426,12 @@ var init_dist = __esm({
|
|
|
410
426
|
if (sharedStateID) {
|
|
411
427
|
output.sharedStateID = sharedStateID;
|
|
412
428
|
}
|
|
429
|
+
if (wrapperModuleId) {
|
|
430
|
+
output.wrapperModuleId = wrapperModuleId;
|
|
431
|
+
}
|
|
432
|
+
if (wrapperUrl) {
|
|
433
|
+
output.wrapperUrl = wrapperUrl;
|
|
434
|
+
}
|
|
413
435
|
return output;
|
|
414
436
|
}
|
|
415
437
|
),
|
|
@@ -454,7 +476,7 @@ ${indentString}`);
|
|
|
454
476
|
indent
|
|
455
477
|
)}`;
|
|
456
478
|
};
|
|
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
|
|
479
|
+
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
480
|
virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
459
481
|
jsx2 = jsxRuntime.jsx;
|
|
460
482
|
promiseForNewWritableStream = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
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.
|
|
28
|
+
"@hubspot/cms-components": "^0.8.1",
|
|
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": "^
|
|
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": "
|
|
103
|
+
"gitHead": "04a7200e723321f2179d2487979aa32f9b6690c6"
|
|
101
104
|
}
|
|
Binary file
|