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