@lwrjs/lwc-ssr 0.24.2 → 0.24.4
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/build/cjs/__mocks__/renderer.cjs +17 -5
- package/build/cjs/__mocks__/undici.cjs +23 -10
- package/build/cjs/dataViewTransformer/index.cjs +53 -47
- package/build/cjs/directFetch.cjs +27 -28
- package/build/cjs/fetchController.cjs +119 -97
- package/build/cjs/moduleLoader.cjs +82 -49
- package/build/cjs/renderer.cjs +290 -189
- package/build/cjs/resourceProvider.cjs +61 -51
- package/build/cjs/serverBootstrapServices.cjs +34 -31
- package/build/cjs/utils.cjs +51 -44
- package/build/cjs/viewProvider/index.cjs +82 -56
- package/build/cjs/viewTransformer/index.cjs +81 -64
- package/package.json +8 -8
package/build/cjs/renderer.cjs
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
5
|
var __export = (target, all) => {
|
|
9
6
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
8
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
14
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
15
|
+
return to;
|
|
22
16
|
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
18
|
|
|
24
19
|
// packages/@lwrjs/lwc-ssr/src/renderer.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
20
|
+
var renderer_exports = {};
|
|
21
|
+
__export(renderer_exports, {
|
|
27
22
|
Renderer: () => Renderer,
|
|
28
23
|
getRenderer: () => getRenderer
|
|
29
24
|
});
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
25
|
+
module.exports = __toCommonJS(renderer_exports);
|
|
26
|
+
var import_lru_cache = require("lru-cache");
|
|
27
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
28
|
+
var import_config = require("@lwrjs/config");
|
|
29
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
30
|
+
var import_instrumentation = require("@lwrjs/instrumentation");
|
|
31
|
+
var import_utils = require("./utils.cjs");
|
|
32
|
+
var import_moduleLoader = require("./moduleLoader.cjs");
|
|
33
|
+
var import_serverBootstrapServices = require("./serverBootstrapServices.cjs");
|
|
38
34
|
var singleton;
|
|
39
35
|
function getRenderer(config, bundleRegistry, resourceRegistry) {
|
|
40
36
|
if (!singleton) {
|
|
@@ -43,8 +39,13 @@ function getRenderer(config, bundleRegistry, resourceRegistry) {
|
|
|
43
39
|
return singleton;
|
|
44
40
|
}
|
|
45
41
|
var Renderer = class {
|
|
42
|
+
config;
|
|
43
|
+
bundleRegistry;
|
|
44
|
+
resourceRegistry;
|
|
45
|
+
contextPerEnv;
|
|
46
|
+
pendingRenders;
|
|
47
|
+
globalCache = {};
|
|
46
48
|
constructor(config, bundleRegistry, resourceRegistry) {
|
|
47
|
-
this.globalCache = {};
|
|
48
49
|
this.config = config;
|
|
49
50
|
this.bundleRegistry = bundleRegistry;
|
|
50
51
|
this.resourceRegistry = resourceRegistry;
|
|
@@ -61,6 +62,22 @@ var Renderer = class {
|
|
|
61
62
|
const taskPoolSize = 1;
|
|
62
63
|
this.pendingRenders = new import_shared_utils.TaskPool(taskPoolSize);
|
|
63
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Render components to HTML strings
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* The rendering flow is as follows:
|
|
70
|
+
* 1. invoke `getServerData`
|
|
71
|
+
* 2. execute the route's SSR bootstrap services
|
|
72
|
+
* 3. render the component to HTML
|
|
73
|
+
*
|
|
74
|
+
* @param components - group of components to render
|
|
75
|
+
* @param route - route configuration
|
|
76
|
+
* @param runtimeEnvironment - environment context
|
|
77
|
+
* @param runtimeParams - request context
|
|
78
|
+
* @param serverData - render data TODO serverData is modified (add test?)
|
|
79
|
+
* @returns render results per component
|
|
80
|
+
*/
|
|
64
81
|
async render(components, route, runtimeEnvironment, runtimeParams, serverData = {}, isFirstOf2PassSSR) {
|
|
65
82
|
let result;
|
|
66
83
|
if ((0, import_shared_utils.isLambdaEnv)() || process.env.SSR_TIMEOUT !== void 0) {
|
|
@@ -76,13 +93,29 @@ var Renderer = class {
|
|
|
76
93
|
result = await this.pendingRenders.execute(async () => {
|
|
77
94
|
return Promise.race([
|
|
78
95
|
timeout,
|
|
79
|
-
|
|
96
|
+
// todo: abort the render if timeout occurs
|
|
97
|
+
this.renderComponents(
|
|
98
|
+
components,
|
|
99
|
+
route,
|
|
100
|
+
runtimeEnvironment,
|
|
101
|
+
runtimeParams,
|
|
102
|
+
serverData,
|
|
103
|
+
isFirstOf2PassSSR,
|
|
104
|
+
abortController
|
|
105
|
+
)
|
|
80
106
|
]);
|
|
81
107
|
});
|
|
82
108
|
clearTimeout(timerId);
|
|
83
109
|
} else {
|
|
84
110
|
result = await this.pendingRenders.execute(async () => {
|
|
85
|
-
return this.renderComponents(
|
|
111
|
+
return this.renderComponents(
|
|
112
|
+
components,
|
|
113
|
+
route,
|
|
114
|
+
runtimeEnvironment,
|
|
115
|
+
runtimeParams,
|
|
116
|
+
serverData,
|
|
117
|
+
isFirstOf2PassSSR
|
|
118
|
+
);
|
|
86
119
|
});
|
|
87
120
|
}
|
|
88
121
|
return result;
|
|
@@ -96,18 +129,41 @@ var Renderer = class {
|
|
|
96
129
|
let loader, bootstrapServiceEvaluationMap;
|
|
97
130
|
try {
|
|
98
131
|
let lwcEngine, serverBootstrapServices;
|
|
99
|
-
({bootstrapServiceEvaluationMap, loader, lwcEngine, serverBootstrapServices} = await this.createLoader(
|
|
132
|
+
({ bootstrapServiceEvaluationMap, loader, lwcEngine, serverBootstrapServices } = await this.createLoader(
|
|
133
|
+
components,
|
|
134
|
+
route,
|
|
135
|
+
serverData,
|
|
136
|
+
isFirstOf2PassSSR,
|
|
137
|
+
services,
|
|
138
|
+
runtimeEnvironment,
|
|
139
|
+
runtimeParams,
|
|
140
|
+
abortController
|
|
141
|
+
));
|
|
100
142
|
const componentModules = await this.loadAppCode(components, route, roots, loader);
|
|
101
|
-
await this.executeDataServices(
|
|
143
|
+
await this.executeDataServices(
|
|
144
|
+
components,
|
|
145
|
+
route,
|
|
146
|
+
serverBootstrapServices,
|
|
147
|
+
componentModules,
|
|
148
|
+
serverData,
|
|
149
|
+
results,
|
|
150
|
+
warnings,
|
|
151
|
+
runtimeEnvironment,
|
|
152
|
+
runtimeParams
|
|
153
|
+
);
|
|
102
154
|
if (!route.bootstrap.ssr) {
|
|
103
|
-
return {results, warnings, bundles: loader?.getBundles()};
|
|
155
|
+
return { results, warnings, bundles: loader?.getBundles() };
|
|
104
156
|
}
|
|
105
157
|
loader?.getFetchController().enableNoOpFetch();
|
|
106
158
|
for (const component of componentModules) {
|
|
107
|
-
const {html} = await renderToString(
|
|
159
|
+
const { html } = await renderToString(
|
|
160
|
+
lwcEngine.module,
|
|
161
|
+
component,
|
|
162
|
+
results[component.specifier].props
|
|
163
|
+
);
|
|
108
164
|
results[component.specifier].html = html;
|
|
109
165
|
}
|
|
110
|
-
return {results, warnings, bundles: loader?.getBundles()};
|
|
166
|
+
return { results, warnings, bundles: loader?.getBundles() };
|
|
111
167
|
} finally {
|
|
112
168
|
loader?.getFetchController().disableNoOpFetch();
|
|
113
169
|
loader?.getFetchController().enableFetchKillSwitch();
|
|
@@ -121,114 +177,141 @@ var Renderer = class {
|
|
|
121
177
|
}
|
|
122
178
|
}
|
|
123
179
|
async loadAppCode(components, route, roots, loader) {
|
|
124
|
-
return await (0, import_instrumentation.getTracer)().trace(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}, async (span) => {
|
|
131
|
-
return import_instrumentation.cacheCountStore.startCacheContext(async () => {
|
|
132
|
-
try {
|
|
133
|
-
const ret = await Promise.all(roots.map((specifier) => loader?.load(specifier)));
|
|
134
|
-
const context = import_instrumentation.cacheCountStore.getCache();
|
|
135
|
-
if (context) {
|
|
136
|
-
span.setAttributes(context);
|
|
137
|
-
}
|
|
138
|
-
return ret;
|
|
139
|
-
} finally {
|
|
140
|
-
import_instrumentation.cacheCountStore.resetCache();
|
|
180
|
+
return await (0, import_instrumentation.getTracer)().trace(
|
|
181
|
+
{
|
|
182
|
+
name: import_instrumentation.ViewSpan.LoadAppCode,
|
|
183
|
+
attributes: {
|
|
184
|
+
components: Object.keys(components).join(","),
|
|
185
|
+
routeId: route.id
|
|
141
186
|
}
|
|
142
|
-
}
|
|
143
|
-
|
|
187
|
+
},
|
|
188
|
+
async (span) => {
|
|
189
|
+
return import_instrumentation.cacheCountStore.startCacheContext(async () => {
|
|
190
|
+
try {
|
|
191
|
+
const ret = await Promise.all(roots.map((specifier) => loader?.load(specifier)));
|
|
192
|
+
const context = import_instrumentation.cacheCountStore.getCache();
|
|
193
|
+
if (context) {
|
|
194
|
+
span.setAttributes(context);
|
|
195
|
+
}
|
|
196
|
+
return ret;
|
|
197
|
+
} finally {
|
|
198
|
+
import_instrumentation.cacheCountStore.resetCache();
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
);
|
|
144
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Run bootstrap services and fetch server data
|
|
206
|
+
*/
|
|
145
207
|
async executeDataServices(components, route, serverBootstrapServices, componentModules, serverData, results, warnings, runtimeEnvironment, runtimeParams) {
|
|
146
|
-
return (0, import_instrumentation.getTracer)().trace(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}, async () => {
|
|
153
|
-
if (serverBootstrapServices) {
|
|
154
|
-
const cookies = route.bootstrap.includeCookiesForSSR && runtimeParams.cookie ? (0, import_shared_utils.cookieStringToObject)(runtimeParams.cookie) : null;
|
|
155
|
-
serverBootstrapServices.evaluateRequestHooks({cookies});
|
|
156
|
-
}
|
|
157
|
-
for (const component of componentModules) {
|
|
158
|
-
const {props} = components[component.specifier];
|
|
159
|
-
if (!component.module.getServerData) {
|
|
160
|
-
results[component.specifier] = {props};
|
|
161
|
-
continue;
|
|
208
|
+
return (0, import_instrumentation.getTracer)().trace(
|
|
209
|
+
{
|
|
210
|
+
name: import_instrumentation.ViewSpan.ExecuteServices,
|
|
211
|
+
attributes: {
|
|
212
|
+
components: Object.keys(components).join(","),
|
|
213
|
+
routeId: route.id
|
|
162
214
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
215
|
+
},
|
|
216
|
+
async () => {
|
|
217
|
+
if (serverBootstrapServices) {
|
|
218
|
+
const cookies = route.bootstrap.includeCookiesForSSR && runtimeParams.cookie ? (0, import_shared_utils.cookieStringToObject)(runtimeParams.cookie) : null;
|
|
219
|
+
serverBootstrapServices.evaluateRequestHooks({ cookies });
|
|
220
|
+
}
|
|
221
|
+
for (const component of componentModules) {
|
|
222
|
+
const { props } = components[component.specifier];
|
|
223
|
+
if (!component.module.getServerData) {
|
|
224
|
+
results[component.specifier] = { props };
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const context = {
|
|
228
|
+
props,
|
|
229
|
+
url: runtimeParams.url,
|
|
230
|
+
params: runtimeParams.params || {},
|
|
231
|
+
query: runtimeParams.query || {},
|
|
232
|
+
locale: runtimeParams.locale || runtimeEnvironment.i18n?.defaultLocale,
|
|
233
|
+
basePath: runtimeParams.basePath || runtimeEnvironment.basePath,
|
|
234
|
+
crossRequestCache: this.globalCache
|
|
235
|
+
};
|
|
236
|
+
const data = await getServerData(component, context, serverData);
|
|
237
|
+
if (data) {
|
|
238
|
+
results[component.specifier] = data;
|
|
239
|
+
}
|
|
240
|
+
data.warnings && warnings.push(...data.warnings);
|
|
241
|
+
}
|
|
242
|
+
if (serverBootstrapServices) {
|
|
243
|
+
serverBootstrapServices.evaluateServerDataHooks(serverData);
|
|
175
244
|
}
|
|
176
|
-
data.warnings && warnings.push(...data.warnings);
|
|
177
|
-
}
|
|
178
|
-
if (serverBootstrapServices) {
|
|
179
|
-
serverBootstrapServices.evaluateServerDataHooks(serverData);
|
|
180
245
|
}
|
|
181
|
-
|
|
246
|
+
);
|
|
182
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Create and initialize the loader and LWC engine for SSR
|
|
250
|
+
*/
|
|
183
251
|
async createLoader(components, route, serverData, isFirstOf2PassSSR, services, runtimeEnvironment, runtimeParams, abortController) {
|
|
184
|
-
return (0, import_instrumentation.getTracer)().trace(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
252
|
+
return (0, import_instrumentation.getTracer)().trace(
|
|
253
|
+
{
|
|
254
|
+
name: import_instrumentation.ViewSpan.CreateLoader,
|
|
255
|
+
attributes: {
|
|
256
|
+
components: Object.keys(components).join(","),
|
|
257
|
+
routeId: route.id
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
async (span) => {
|
|
261
|
+
return import_instrumentation.cacheCountStore.startCacheContext(async () => {
|
|
262
|
+
try {
|
|
263
|
+
const bootstrapContext = this.getCachedBootstrapContext(
|
|
264
|
+
route,
|
|
265
|
+
runtimeEnvironment,
|
|
266
|
+
runtimeParams,
|
|
267
|
+
serverData,
|
|
268
|
+
isFirstOf2PassSSR,
|
|
269
|
+
abortController
|
|
270
|
+
);
|
|
271
|
+
const bootstrapServiceEvaluationMap = bootstrapContext.bootstrapServiceEvaluationMap;
|
|
272
|
+
const loader = await bootstrapContext.loader;
|
|
273
|
+
loader.clearBundles();
|
|
274
|
+
const fetchController = loader.getFetchController();
|
|
275
|
+
this.resetFetchController(fetchController, runtimeParams, route, abortController);
|
|
276
|
+
const ssrCompilerEnabled = (0, import_shared_utils.getFeatureFlags)().SSR_COMPILER_ENABLED === true;
|
|
277
|
+
const engineServerSpecifier = (0, import_shared_utils.getSpecifier)({
|
|
278
|
+
specifier: ssrCompilerEnabled ? "@lwc/ssr-runtime" : "@lwc/engine-server",
|
|
279
|
+
version: route.bootstrap.lwcVersion
|
|
280
|
+
});
|
|
281
|
+
const lwcEngine = await loader?.load(engineServerSpecifier, ["lwc"]);
|
|
282
|
+
const is2ndPass = route.contentTemplate && route.contentTemplate.component && !isFirstOf2PassSSR;
|
|
283
|
+
const needsBootstrap = !bootstrapServiceEvaluationMap?.has(route.id);
|
|
284
|
+
let serverBootstrapServices;
|
|
285
|
+
if (!is2ndPass || needsBootstrap) {
|
|
286
|
+
bootstrapServiceEvaluationMap?.set(route.id, true);
|
|
287
|
+
const serviceModules = await Promise.all(
|
|
288
|
+
services.map((specifier) => loader?.load(specifier))
|
|
289
|
+
);
|
|
290
|
+
serverBootstrapServices = (0, import_serverBootstrapServices.createServerBootstrapServices)(loader);
|
|
291
|
+
for (const service of serviceModules) {
|
|
292
|
+
await (0, import_serverBootstrapServices.evaluateServerBootstrapModule)(
|
|
293
|
+
service,
|
|
294
|
+
serverBootstrapServices.serviceAPI
|
|
295
|
+
);
|
|
296
|
+
}
|
|
214
297
|
}
|
|
298
|
+
const ret = {
|
|
299
|
+
bootstrapServiceEvaluationMap,
|
|
300
|
+
loader,
|
|
301
|
+
lwcEngine,
|
|
302
|
+
serverBootstrapServices
|
|
303
|
+
};
|
|
304
|
+
const context = import_instrumentation.cacheCountStore.getCache();
|
|
305
|
+
if (context) {
|
|
306
|
+
span.setAttributes(context);
|
|
307
|
+
}
|
|
308
|
+
return ret;
|
|
309
|
+
} finally {
|
|
310
|
+
import_instrumentation.cacheCountStore.resetCache();
|
|
215
311
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
lwcEngine,
|
|
220
|
-
serverBootstrapServices
|
|
221
|
-
};
|
|
222
|
-
const context = import_instrumentation.cacheCountStore.getCache();
|
|
223
|
-
if (context) {
|
|
224
|
-
span.setAttributes(context);
|
|
225
|
-
}
|
|
226
|
-
return ret;
|
|
227
|
-
} finally {
|
|
228
|
-
import_instrumentation.cacheCountStore.resetCache();
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
);
|
|
232
315
|
}
|
|
233
316
|
resetFetchController(fetchController, runtimeParams, route, abortController) {
|
|
234
317
|
fetchController.disableFetchKillSwitch();
|
|
@@ -238,7 +321,7 @@ var Renderer = class {
|
|
|
238
321
|
};
|
|
239
322
|
fetchController.setFetchRequestContext({
|
|
240
323
|
host: runtimeParams.host,
|
|
241
|
-
headers: route.bootstrap.includeCookiesForSSR ? {Cookie: runtimeParams.cookie, ...baseHeaders} : baseHeaders,
|
|
324
|
+
headers: route.bootstrap.includeCookiesForSSR ? { Cookie: runtimeParams.cookie, ...baseHeaders } : baseHeaders,
|
|
242
325
|
abortController
|
|
243
326
|
});
|
|
244
327
|
}
|
|
@@ -246,12 +329,21 @@ var Renderer = class {
|
|
|
246
329
|
let loader, bootstrapServiceEvaluationMap;
|
|
247
330
|
const envContext = (0, import_shared_utils.buildEnvironmentContext)(runtimeParams);
|
|
248
331
|
const appLwcVersion = route.bootstrap?.lwcVersion ?? import_config.LWC_VERSION;
|
|
249
|
-
const versions = {lwrVersion: route.bootstrap?.lwrVersion, lwcVersion: appLwcVersion};
|
|
250
|
-
const contextCacheKey = (0, import_shared_utils.getCacheKeyFromJson)({envContext, versions});
|
|
332
|
+
const versions = { lwrVersion: route.bootstrap?.lwrVersion, lwcVersion: appLwcVersion };
|
|
333
|
+
const contextCacheKey = (0, import_shared_utils.getCacheKeyFromJson)({ envContext, versions });
|
|
251
334
|
const bootstrapContext = this.contextPerEnv.get(contextCacheKey);
|
|
252
335
|
if (!bootstrapContext || (0, import_shared_utils.isLocalDev)() && isFirstOf2PassSSR || (0, import_shared_utils.getFeatureFlags)().SSR_LOADER_PER_REQUEST) {
|
|
253
|
-
loader = (0, import_moduleLoader.createModuleLoader)(
|
|
254
|
-
|
|
336
|
+
loader = (0, import_moduleLoader.createModuleLoader)(
|
|
337
|
+
this.config,
|
|
338
|
+
this.resourceRegistry,
|
|
339
|
+
this.bundleRegistry,
|
|
340
|
+
runtimeEnvironment,
|
|
341
|
+
runtimeParams,
|
|
342
|
+
serverData,
|
|
343
|
+
route.bootstrap,
|
|
344
|
+
abortController
|
|
345
|
+
);
|
|
346
|
+
bootstrapServiceEvaluationMap = /* @__PURE__ */ new Map();
|
|
255
347
|
this.contextPerEnv.set(contextCacheKey, {
|
|
256
348
|
loader,
|
|
257
349
|
bootstrapServiceEvaluationMap
|
|
@@ -267,66 +359,75 @@ var Renderer = class {
|
|
|
267
359
|
}
|
|
268
360
|
};
|
|
269
361
|
function getServerData(component, context, serverData) {
|
|
270
|
-
return (0, import_instrumentation.getTracer)().trace(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if (dataProviderMetrics) {
|
|
283
|
-
const {success: dataProviderSuccess, warnings: dataProviderWarnings} = dataProviderMetrics;
|
|
284
|
-
if (dataProviderSuccess && dataProviderSuccess.length > 0) {
|
|
285
|
-
span.setAttributes({dataProviderSuccess});
|
|
362
|
+
return (0, import_instrumentation.getTracer)().trace(
|
|
363
|
+
{
|
|
364
|
+
name: import_instrumentation.ViewSpan.GetServerData,
|
|
365
|
+
attributes: { specifier: component.specifier }
|
|
366
|
+
},
|
|
367
|
+
async (span) => {
|
|
368
|
+
try {
|
|
369
|
+
const data = await component.module.getServerData(context);
|
|
370
|
+
Object.assign(serverData, data.props);
|
|
371
|
+
if (data.warnings) {
|
|
372
|
+
const warnings = data.warnings.map((w) => (0, import_diagnostics.stringifyError)(w)).join(", ");
|
|
373
|
+
span.setAttributes({ warnings });
|
|
286
374
|
}
|
|
287
|
-
|
|
288
|
-
|
|
375
|
+
const dataProviderMetrics = data.props?.metrics?.dataProvider;
|
|
376
|
+
if (dataProviderMetrics) {
|
|
377
|
+
const { success: dataProviderSuccess, warnings: dataProviderWarnings } = dataProviderMetrics;
|
|
378
|
+
if (dataProviderSuccess && dataProviderSuccess.length > 0) {
|
|
379
|
+
span.setAttributes({ dataProviderSuccess });
|
|
380
|
+
}
|
|
381
|
+
if (dataProviderWarnings && dataProviderWarnings.length > 0) {
|
|
382
|
+
span.setAttributes({ dataProviderWarnings });
|
|
383
|
+
}
|
|
289
384
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
delete data.props.metrics;
|
|
293
|
-
}
|
|
294
|
-
return data;
|
|
295
|
-
} catch (e) {
|
|
296
|
-
if (e instanceof import_diagnostics.LwrError)
|
|
297
|
-
throw e;
|
|
298
|
-
const statusError = e;
|
|
299
|
-
if (typeof statusError.status === "number") {
|
|
300
|
-
throw new import_diagnostics.LwrStatusError(statusError.message, statusError.status, statusError.headers);
|
|
301
|
-
}
|
|
302
|
-
if (e.dataProviderFailed) {
|
|
303
|
-
const dataProviderFailed = e.dataProviderFailed;
|
|
304
|
-
if (dataProviderFailed.length > 0) {
|
|
305
|
-
span.setAttributes({dataProviderFailed});
|
|
385
|
+
if (data.props?.metrics) {
|
|
386
|
+
delete data.props.metrics;
|
|
306
387
|
}
|
|
388
|
+
return data;
|
|
389
|
+
} catch (e) {
|
|
390
|
+
if (e instanceof import_diagnostics.LwrError) throw e;
|
|
391
|
+
const statusError = e;
|
|
392
|
+
if (typeof statusError.status === "number") {
|
|
393
|
+
throw new import_diagnostics.LwrStatusError(statusError.message, statusError.status, statusError.headers);
|
|
394
|
+
}
|
|
395
|
+
if (e.dataProviderFailed) {
|
|
396
|
+
const dataProviderFailed = e.dataProviderFailed;
|
|
397
|
+
if (dataProviderFailed.length > 0) {
|
|
398
|
+
span.setAttributes({ dataProviderFailed });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
throw new import_diagnostics.LwrApplicationError(
|
|
402
|
+
`Error in "getServerData" for "${component.specifier}": ${(0, import_diagnostics.stringifyError)(e)}`
|
|
403
|
+
);
|
|
307
404
|
}
|
|
308
|
-
throw new import_diagnostics.LwrApplicationError(`Error in "getServerData" for "${component.specifier}": ${(0, import_diagnostics.stringifyError)(e)}`);
|
|
309
405
|
}
|
|
310
|
-
|
|
406
|
+
);
|
|
311
407
|
}
|
|
312
408
|
async function renderToString(engine, component, props) {
|
|
313
409
|
const isSSRv2 = (0, import_shared_utils.getFeatureFlags)().SSR_COMPILER_ENABLED || false;
|
|
314
|
-
return (0, import_instrumentation.getTracer)().trace(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
410
|
+
return (0, import_instrumentation.getTracer)().trace(
|
|
411
|
+
{
|
|
412
|
+
name: import_instrumentation.ViewSpan.RenderComponent,
|
|
413
|
+
attributes: { specifier: component.specifier, isSSRv2 }
|
|
414
|
+
},
|
|
415
|
+
async () => {
|
|
416
|
+
try {
|
|
417
|
+
const elementName = (0, import_shared_utils.moduleSpecifierToKebabCase)(component.specifier);
|
|
418
|
+
const moduleDefault = component.module.default;
|
|
419
|
+
const html = isSSRv2 ? (
|
|
420
|
+
// serverSideRenderComponent(tagName: string, Component: ComponentWithGenerateMarkup, props: Properties = {}, styleDedupe: boolean | string = true, mode: CompilationMode = DEFAULT_SSR_MODE / 'sync'
|
|
421
|
+
await engine.renderComponent(elementName, moduleDefault, props, elementName, "sync")
|
|
422
|
+
) : engine.renderComponent(elementName, moduleDefault, props);
|
|
423
|
+
return { html };
|
|
424
|
+
} catch (e) {
|
|
425
|
+
if (e instanceof import_diagnostics.LwrError) throw e;
|
|
426
|
+
const error = Object(e);
|
|
427
|
+
const message = error.message ?? (0, import_diagnostics.stringifyError)(e);
|
|
428
|
+
const detailedMessage = error.wcStack ? "An error occurred during server-side rendering for component stack: " + error.wcStack + ". Error was: " + message : `An error occurred during server-side rendering "${component.specifier}": ` + message;
|
|
429
|
+
throw new import_diagnostics.LwrApplicationError(detailedMessage);
|
|
430
|
+
}
|
|
330
431
|
}
|
|
331
|
-
|
|
432
|
+
);
|
|
332
433
|
}
|