@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
|
@@ -1,16 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
6
|
var __export = (target, all) => {
|
|
4
7
|
for (var name in all)
|
|
5
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
9
|
};
|
|
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 });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
7
19
|
|
|
8
20
|
// packages/@lwrjs/lwc-ssr/src/__mocks__/renderer.ts
|
|
9
|
-
|
|
10
|
-
__export(
|
|
21
|
+
var renderer_exports = {};
|
|
22
|
+
__export(renderer_exports, {
|
|
11
23
|
Renderer: () => Renderer,
|
|
12
24
|
getRenderer: () => getRenderer
|
|
13
25
|
});
|
|
26
|
+
module.exports = __toCommonJS(renderer_exports);
|
|
14
27
|
var mockComponents = {};
|
|
15
28
|
function getRenderer() {
|
|
16
29
|
return new Renderer();
|
|
@@ -37,6 +50,6 @@ var Renderer = class {
|
|
|
37
50
|
throw new Error(mockOutput.error);
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
|
-
return {results, warnings, bundles: new Set([2, 3, 4])};
|
|
53
|
+
return { results, warnings, bundles: /* @__PURE__ */ new Set([2, 3, 4]) };
|
|
41
54
|
}
|
|
42
55
|
};
|
|
@@ -1,30 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
6
|
var __export = (target, all) => {
|
|
4
7
|
for (var name in all)
|
|
5
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
9
|
};
|
|
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 });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
7
19
|
|
|
8
20
|
// packages/@lwrjs/lwc-ssr/src/__mocks__/undici.ts
|
|
9
|
-
|
|
10
|
-
__export(
|
|
21
|
+
var undici_exports = {};
|
|
22
|
+
__export(undici_exports, {
|
|
11
23
|
Pool: () => Pool
|
|
12
24
|
});
|
|
25
|
+
module.exports = __toCommonJS(undici_exports);
|
|
13
26
|
var Pool = class {
|
|
27
|
+
// passed to the Pool constructor
|
|
14
28
|
constructor(origin) {
|
|
15
29
|
this.origin = "";
|
|
16
30
|
this.origin = origin;
|
|
17
31
|
}
|
|
18
32
|
async request(options) {
|
|
19
|
-
const {path} = options;
|
|
20
|
-
if (path.endsWith("bad"))
|
|
21
|
-
|
|
22
|
-
const ret = {origin: this.origin, req: options};
|
|
33
|
+
const { path } = options;
|
|
34
|
+
if (path.endsWith("bad")) throw new Error("fail");
|
|
35
|
+
const ret = { origin: this.origin, req: options };
|
|
23
36
|
const retStr = JSON.stringify(ret);
|
|
24
37
|
return Promise.resolve({
|
|
25
38
|
statusCode: path.endsWith("fail") ? 500 : path.endsWith("empty") ? 204 : path.endsWith("reset") ? 205 : 200,
|
|
26
|
-
headers: {"cache-control": "no-cache", "X-something": void 0, "set-cookie": ["a", "b", "c"]},
|
|
39
|
+
headers: { "cache-control": "no-cache", "X-something": void 0, "set-cookie": ["a", "b", "c"] },
|
|
27
40
|
body: {
|
|
41
|
+
// return options passed to new Pool() and client.request()
|
|
28
42
|
arrayBuffer: () => Promise.resolve(Uint8Array.from(retStr.split("").map((letter) => letter.charCodeAt(0)))),
|
|
29
43
|
text: () => Promise.resolve(retStr),
|
|
30
44
|
json: () => Promise.resolve(ret)
|
|
@@ -1,82 +1,89 @@
|
|
|
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/dataViewTransformer/index.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
27
23
|
default: () => preloadDataViewTransformer
|
|
28
24
|
});
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
27
|
+
var import_instrumentation = require("@lwrjs/instrumentation");
|
|
28
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
29
|
+
var import_utils = require("../utils.cjs");
|
|
30
|
+
var import_renderer = require("../renderer.cjs");
|
|
34
31
|
var NAME = "preload-data-transformer";
|
|
35
|
-
function preloadDataViewTransformer(_options, {config, moduleBundler, resourceRegistry}) {
|
|
32
|
+
function preloadDataViewTransformer(_options, { config, moduleBundler, resourceRegistry }) {
|
|
36
33
|
const routes = [...config.routes, ...config.errorRoutes];
|
|
37
34
|
return {
|
|
38
35
|
name: NAME,
|
|
39
36
|
async link(stringBuilder, viewContext, metadata) {
|
|
40
|
-
const allBundles = new Set([...metadata.serverBundles ?? []]);
|
|
41
|
-
const {rootComponent} = viewContext.view;
|
|
37
|
+
const allBundles = /* @__PURE__ */ new Set([...metadata.serverBundles ?? []]);
|
|
38
|
+
const { rootComponent } = viewContext.view;
|
|
42
39
|
if (!rootComponent || !viewContext.view.bootstrap?.preloadData || viewContext.view.bootstrap?.ssr) {
|
|
43
40
|
return {};
|
|
44
41
|
}
|
|
45
|
-
import_diagnostics.logger.debug({label: NAME, message: `Preload data for root component "${rootComponent}"`});
|
|
42
|
+
import_diagnostics.logger.debug({ label: NAME, message: `Preload data for root component "${rootComponent}"` });
|
|
46
43
|
const {
|
|
47
44
|
results = {},
|
|
48
45
|
warnings,
|
|
49
46
|
bundles
|
|
50
|
-
} = await (0, import_instrumentation.getTracer)().trace(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
} = await (0, import_instrumentation.getTracer)().trace(
|
|
48
|
+
{
|
|
49
|
+
name: import_instrumentation.ViewSpan.PreloadData,
|
|
50
|
+
attributes: { rootComponent }
|
|
51
|
+
},
|
|
52
|
+
async () => {
|
|
53
|
+
const route = routes.find((r) => r.id === viewContext.view.id);
|
|
54
|
+
if (!route) {
|
|
55
|
+
throw new Error(`Unable to resolve configuration for view: ${viewContext.view.id}`);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
return await (0, import_renderer.getRenderer)(config, moduleBundler, resourceRegistry).render(
|
|
59
|
+
{ [rootComponent]: { specifier: rootComponent, props: {} } },
|
|
60
|
+
route,
|
|
61
|
+
viewContext.runtimeEnvironment,
|
|
62
|
+
viewContext.runtimeParams
|
|
63
|
+
);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
if (e instanceof import_diagnostics.LwrStatusError) throw e;
|
|
66
|
+
const message = import_diagnostics.descriptions.APPLICATION.PRELOAD_DATA_ERROR(
|
|
67
|
+
rootComponent,
|
|
68
|
+
(0, import_diagnostics.stringifyError)(e)
|
|
69
|
+
);
|
|
70
|
+
import_diagnostics.logger.warn({ label: "preloadDataViewTransformer", message });
|
|
71
|
+
return { warnings: [message] };
|
|
72
|
+
}
|
|
66
73
|
}
|
|
67
|
-
|
|
74
|
+
);
|
|
68
75
|
(0, import_utils.mergeWarnings)(metadata, warnings);
|
|
69
76
|
const result = results[rootComponent];
|
|
70
77
|
if (!result) {
|
|
71
78
|
return {};
|
|
72
79
|
}
|
|
73
|
-
const {props, markup, cache: {ttl} = {ttl: void 0}} = result || {};
|
|
74
|
-
import_diagnostics.logger.verbose({label: NAME, message: "response", additionalInfo: props});
|
|
80
|
+
const { props, markup, cache: { ttl } = { ttl: void 0 } } = result || {};
|
|
81
|
+
import_diagnostics.logger.verbose({ label: NAME, message: "response", additionalInfo: props });
|
|
75
82
|
markup && (0, import_shared_utils.addHeadMarkup)([result.markup], stringBuilder);
|
|
76
83
|
metadata.serverData = metadata.serverData || {};
|
|
77
84
|
Object.assign(metadata.serverData, props);
|
|
78
|
-
metadata.serverBundles = bundles ? new Set([...allBundles, ...bundles]) : allBundles;
|
|
79
|
-
return {cache: {ttl}};
|
|
85
|
+
metadata.serverBundles = bundles ? /* @__PURE__ */ new Set([...allBundles, ...bundles]) : allBundles;
|
|
86
|
+
return { cache: { ttl } };
|
|
80
87
|
}
|
|
81
88
|
};
|
|
82
89
|
}
|
|
@@ -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/directFetch.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
21
|
+
var directFetch_exports = {};
|
|
22
|
+
__export(directFetch_exports, {
|
|
27
23
|
ROUTE_CORE_HEADER: () => ROUTE_CORE_HEADER,
|
|
28
24
|
fetchWithAgent: () => fetchWithAgent
|
|
29
25
|
});
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
26
|
+
module.exports = __toCommonJS(directFetch_exports);
|
|
27
|
+
var import_undici = require("undici");
|
|
28
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
29
|
+
var import_utils = require("./utils.cjs");
|
|
30
|
+
var CORE_CLIENTS = /* @__PURE__ */ new Map();
|
|
34
31
|
var ROUTE_CORE_HEADER = "x-sfdc-route-core";
|
|
35
32
|
async function fetchWithAgent(request, init, forwardedOrigin, coreProxy, span) {
|
|
36
|
-
let {origin, servername} = coreProxy;
|
|
37
|
-
const {finalUrl} = (0, import_utils.getFinalRequest)(request, origin.startsWith("http") ? origin : forwardedOrigin);
|
|
33
|
+
let { origin, servername } = coreProxy;
|
|
34
|
+
const { finalUrl } = (0, import_utils.getFinalRequest)(request, origin.startsWith("http") ? origin : forwardedOrigin);
|
|
38
35
|
const forwardedHostname = (0, import_shared_utils.toHostname)(forwardedOrigin);
|
|
39
36
|
const hostHeader = coreProxy.host ?? forwardedHostname;
|
|
40
37
|
const ENHANCED_DOMAIN_TLD = ".site.com";
|
|
@@ -68,20 +65,23 @@ async function fetchWithAgent(request, init, forwardedOrigin, coreProxy, span) {
|
|
|
68
65
|
}
|
|
69
66
|
const res = await client.request({
|
|
70
67
|
...init,
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
69
|
+
// @ts-ignore - HttpMethod not available for typecasting :|
|
|
71
70
|
method: init.method || "GET",
|
|
72
71
|
path,
|
|
73
|
-
headers: {...init?.headers, Host: hostHeader},
|
|
72
|
+
headers: { ...init?.headers, Host: hostHeader },
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
74
|
+
// @ts-ignore - not properly typed >:|
|
|
74
75
|
servername
|
|
75
76
|
});
|
|
76
|
-
span.setAttributes({coreStatusCode: res.statusCode});
|
|
77
|
+
span.setAttributes({ coreStatusCode: res.statusCode });
|
|
77
78
|
const bodyBuffer = await res.body.arrayBuffer();
|
|
78
79
|
const body = res.statusCode === 204 || res.statusCode === 205 ? null : bodyBuffer;
|
|
79
80
|
const headers = new Headers();
|
|
80
81
|
for (const [key, value] of Object.entries(res.headers)) {
|
|
81
|
-
if (!value)
|
|
82
|
-
continue;
|
|
82
|
+
if (!value) continue;
|
|
83
83
|
const values = Array.isArray(value) ? value : [value];
|
|
84
84
|
values.forEach((v) => headers.append(key, v));
|
|
85
85
|
}
|
|
86
|
-
return new Response(body, {status: res.statusCode, headers});
|
|
86
|
+
return new Response(body, { status: res.statusCode, headers });
|
|
87
87
|
}
|
|
@@ -1,36 +1,33 @@
|
|
|
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/fetchController.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
21
|
+
var fetchController_exports = {};
|
|
22
|
+
__export(fetchController_exports, {
|
|
27
23
|
FetchController: () => FetchController
|
|
28
24
|
});
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
25
|
+
module.exports = __toCommonJS(fetchController_exports);
|
|
26
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
27
|
+
var import_instrumentation = require("@lwrjs/instrumentation");
|
|
28
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
29
|
+
var import_directFetch = require("./directFetch.cjs");
|
|
30
|
+
var import_utils = require("./utils.cjs");
|
|
34
31
|
var FetchController = class {
|
|
35
32
|
constructor(context, coreProxy) {
|
|
36
33
|
this.killSwitchActivated = false;
|
|
@@ -45,7 +42,7 @@ var FetchController = class {
|
|
|
45
42
|
const signal = this.abortController?.signal;
|
|
46
43
|
const updatedInit = {
|
|
47
44
|
...init,
|
|
48
|
-
headers: {...init?.headers, ...this.headers},
|
|
45
|
+
headers: { ...init?.headers, ...this.headers },
|
|
49
46
|
signal
|
|
50
47
|
};
|
|
51
48
|
const fetchFunction = this.noOpActivated ? this.fetchNoOp(request, updatedInit) : this.fetchEndowment(request, updatedInit);
|
|
@@ -59,6 +56,9 @@ var FetchController = class {
|
|
|
59
56
|
});
|
|
60
57
|
return fetchPromise;
|
|
61
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* After SSR is complete the kill switch will abort any pending fetch requests.
|
|
61
|
+
*/
|
|
62
62
|
this.activateKillSwitch = () => {
|
|
63
63
|
this.killSwitchActivated = true;
|
|
64
64
|
this.abortController?.abort("AbortError: Kill switch enabled");
|
|
@@ -67,6 +67,10 @@ var FetchController = class {
|
|
|
67
67
|
this.deactivateKillSwitch = () => {
|
|
68
68
|
this.killSwitchActivated = false;
|
|
69
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* During SSR renderComponent (which is synchronous) Do not even call any fetch requests
|
|
72
|
+
* since they would not complete before SSR is done.
|
|
73
|
+
*/
|
|
70
74
|
this.activateNoOp = () => {
|
|
71
75
|
this.noOpActivated = true;
|
|
72
76
|
};
|
|
@@ -74,7 +78,7 @@ var FetchController = class {
|
|
|
74
78
|
this.noOpActivated = false;
|
|
75
79
|
};
|
|
76
80
|
this.setFetchRequestContext = (context) => {
|
|
77
|
-
const {abortController, host, headers} = context;
|
|
81
|
+
const { abortController, host, headers } = context;
|
|
78
82
|
this.host = host;
|
|
79
83
|
this.headers = headers;
|
|
80
84
|
this.abortController = abortController;
|
|
@@ -85,9 +89,13 @@ var FetchController = class {
|
|
|
85
89
|
}
|
|
86
90
|
handleAbortError(request, error) {
|
|
87
91
|
const message = `${String(request)} request was killed. Either the request timed out or it was dispatched during SSR. Async processes are not supported during SSR. For more information, see: https://developer.salesforce.com/docs/platform/lwr/guide/lwr-configure-component-ssr.html.`;
|
|
88
|
-
import_diagnostics.logger.warn({label: `Server-side Rendering`, message}, error);
|
|
89
|
-
return Promise.resolve(new Response(message, {status: 500}));
|
|
92
|
+
import_diagnostics.logger.warn({ label: `Server-side Rendering`, message }, error);
|
|
93
|
+
return Promise.resolve(new Response(message, { status: 500 }));
|
|
90
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Create a fetch API that never calls a request.
|
|
97
|
+
* This is not expected to be called without an AbortController setup.
|
|
98
|
+
*/
|
|
91
99
|
fetchNoOp(request, init) {
|
|
92
100
|
return new Promise((resolve) => {
|
|
93
101
|
if (!init?.signal) {
|
|
@@ -97,7 +105,12 @@ var FetchController = class {
|
|
|
97
105
|
} else {
|
|
98
106
|
const abortHandler = (err) => {
|
|
99
107
|
init?.signal?.removeEventListener("abort", abortHandler);
|
|
100
|
-
resolve(
|
|
108
|
+
resolve(
|
|
109
|
+
this.handleAbortError(
|
|
110
|
+
request,
|
|
111
|
+
new Error("Not allowed: Request was dispatched during SSR", { cause: err })
|
|
112
|
+
)
|
|
113
|
+
);
|
|
101
114
|
};
|
|
102
115
|
init.signal.addEventListener("abort", abortHandler);
|
|
103
116
|
}
|
|
@@ -105,8 +118,8 @@ var FetchController = class {
|
|
|
105
118
|
}
|
|
106
119
|
createFetchEndowment() {
|
|
107
120
|
return (request, init = {}) => {
|
|
108
|
-
const {host: forwardedOrigin = "", coreProxy} = this;
|
|
109
|
-
const {finalRequest, finalUrl} = (0, import_utils.getFinalRequest)(request, forwardedOrigin);
|
|
121
|
+
const { host: forwardedOrigin = "", coreProxy } = this;
|
|
122
|
+
const { finalRequest, finalUrl } = (0, import_utils.getFinalRequest)(request, forwardedOrigin);
|
|
110
123
|
if (coreProxy || forwardedOrigin && finalUrl.startsWith(forwardedOrigin)) {
|
|
111
124
|
init.headers[import_directFetch.ROUTE_CORE_HEADER] = "true";
|
|
112
125
|
}
|
|
@@ -115,31 +128,36 @@ var FetchController = class {
|
|
|
115
128
|
label: `pre ${import_instrumentation.ViewSpan.Fetch}`,
|
|
116
129
|
message: `finalUrl: ${finalUrl}, hasCookies: ${hasCookies}`
|
|
117
130
|
});
|
|
118
|
-
return (0, import_instrumentation.getTracer)().trace(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
131
|
+
return (0, import_instrumentation.getTracer)().trace(
|
|
132
|
+
// fetchType is one of ['cdn' (default), 'direct']
|
|
133
|
+
// Default URL to final URL if successful addInfoToSpan will replace with response.url
|
|
134
|
+
{
|
|
135
|
+
name: import_instrumentation.ViewSpan.Fetch,
|
|
136
|
+
attributes: {
|
|
137
|
+
url: finalUrl,
|
|
138
|
+
fetchType: "cdn",
|
|
139
|
+
forwardedOrigin,
|
|
140
|
+
hasCookies
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
(span) => {
|
|
144
|
+
const withTracing = (fetchPromise) => {
|
|
145
|
+
return fetchPromise.then((res) => {
|
|
146
|
+
res.url && span.setAttributes({ url: res.url });
|
|
147
|
+
span.setAttributes({ statusCode: res.status });
|
|
148
|
+
return res;
|
|
149
|
+
}).catch((e) => {
|
|
150
|
+
span.setAttributes({ error: (0, import_diagnostics.stringifyError)(e) });
|
|
151
|
+
throw e;
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
init.headers = { ...init.headers, ...(0, import_shared_utils.getTraceHeaders)({}, span) };
|
|
155
|
+
if (coreProxy) {
|
|
156
|
+
return withTracing((0, import_directFetch.fetchWithAgent)(request, init, forwardedOrigin, coreProxy, span));
|
|
157
|
+
}
|
|
158
|
+
return withTracing(fetch(finalRequest, init));
|
|
140
159
|
}
|
|
141
|
-
|
|
142
|
-
});
|
|
160
|
+
);
|
|
143
161
|
};
|
|
144
162
|
}
|
|
145
163
|
};
|