@lwrjs/lwc-ssr 0.10.2 → 0.10.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/identity.cjs
CHANGED
|
@@ -10,12 +10,10 @@ __markAsModule(exports);
|
|
|
10
10
|
__export(exports, {
|
|
11
11
|
LWC_SSR_PREFIX: () => LWC_SSR_PREFIX,
|
|
12
12
|
SSR_PROPS_ATTR: () => SSR_PROPS_ATTR,
|
|
13
|
-
SSR_PROPS_KEY: () => SSR_PROPS_KEY,
|
|
14
13
|
getPropsId: () => getPropsId
|
|
15
14
|
});
|
|
16
15
|
var LWC_SSR_PREFIX = "@lwrjs/lwc-ssr/";
|
|
17
16
|
var SSR_PROPS_ATTR = "data-lwr-props-id";
|
|
18
|
-
var SSR_PROPS_KEY = "ssrProps";
|
|
19
17
|
function getPropsId() {
|
|
20
18
|
return `lwcprops${Math.floor(Math.random() * 65536).toString(16)}`;
|
|
21
19
|
}
|
|
@@ -32,12 +32,16 @@ var import_ssr_element = __toModule(require("./ssr-element.cjs"));
|
|
|
32
32
|
function lwcSsrViewTransformer(options, {moduleBundler, resourceRegistry}) {
|
|
33
33
|
return {
|
|
34
34
|
name: "ssr-lwc-transformer",
|
|
35
|
-
async link(stringBuilder, viewContext,
|
|
35
|
+
async link(stringBuilder, viewContext, metadata) {
|
|
36
36
|
if (!viewContext.view.bootstrap?.ssr) {
|
|
37
37
|
return {};
|
|
38
38
|
}
|
|
39
39
|
import_shared_utils.logger.debug("[lwcSsrViewTransformer] link");
|
|
40
40
|
import_shared_utils.logger.verbose("[lwcSsrViewTransformer] link input", stringBuilder);
|
|
41
|
+
if (!metadata.ssrProps) {
|
|
42
|
+
metadata.ssrProps = {};
|
|
43
|
+
}
|
|
44
|
+
const {customElements, ssrProps} = metadata;
|
|
41
45
|
const ssrModules = [];
|
|
42
46
|
for (const [index, {tagName, location, props}] of customElements.entries()) {
|
|
43
47
|
const isCsr = (0, import_shared_utils.isCsrIsland)(props);
|
|
@@ -58,7 +62,6 @@ function lwcSsrViewTransformer(options, {moduleBundler, resourceRegistry}) {
|
|
|
58
62
|
});
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
|
-
const ssrProps = {};
|
|
62
65
|
let ssrLinks = "";
|
|
63
66
|
let pageTtl;
|
|
64
67
|
await Promise.all(ssrModules.map(({index, specifier, tagName, props: rawProps = {}, startOffset, endOffset}) => {
|
|
@@ -93,9 +96,6 @@ function lwcSsrViewTransformer(options, {moduleBundler, resourceRegistry}) {
|
|
|
93
96
|
import_shared_utils.logger.warn(`Server-side rendering for "${specifier}" failed. Falling back to client-side rendering. Reason: `, err.stack);
|
|
94
97
|
});
|
|
95
98
|
}));
|
|
96
|
-
if (Object.keys(ssrProps).length) {
|
|
97
|
-
stringBuilder.prependLeft(ssrModules[0].startOffset, `<script type="application/javascript">globalThis.LWR = globalThis.LWR || {};globalThis.LWR.${import_identity.SSR_PROPS_KEY} = ${JSON.stringify(ssrProps)};</script>`);
|
|
98
|
-
}
|
|
99
99
|
if (ssrLinks) {
|
|
100
100
|
const headIndex = stringBuilder.original.indexOf("</head>");
|
|
101
101
|
if (headIndex >= 0) {
|
package/build/es/identity.d.ts
CHANGED
package/build/es/identity.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HYDRATE_CLIENT_VALUE, HYDRATE_DIRECTIVE, isCsrIsland, isHydrateOnLoad, kebabCaseToModuleSpecifier, logger, shortestTtl, } from '@lwrjs/shared-utils';
|
|
2
|
-
import { LWC_SSR_PREFIX, SSR_PROPS_ATTR,
|
|
2
|
+
import { LWC_SSR_PREFIX, SSR_PROPS_ATTR, getPropsId } from '../identity.js';
|
|
3
3
|
import { ssrElement } from './ssr-element.js';
|
|
4
4
|
/**
|
|
5
5
|
* This is a view transformer run by the view registry during linking of a page document/route (configured in lwr.config.json[routes]).
|
|
@@ -22,12 +22,16 @@ import { ssrElement } from './ssr-element.js';
|
|
|
22
22
|
export default function lwcSsrViewTransformer(options, { moduleBundler, resourceRegistry }) {
|
|
23
23
|
return {
|
|
24
24
|
name: 'ssr-lwc-transformer',
|
|
25
|
-
async link(stringBuilder, viewContext,
|
|
25
|
+
async link(stringBuilder, viewContext, metadata) {
|
|
26
26
|
if (!viewContext.view.bootstrap?.ssr) {
|
|
27
27
|
return {}; // no SSR
|
|
28
28
|
}
|
|
29
29
|
logger.debug('[lwcSsrViewTransformer] link');
|
|
30
30
|
logger.verbose('[lwcSsrViewTransformer] link input', stringBuilder);
|
|
31
|
+
if (!metadata.ssrProps) {
|
|
32
|
+
metadata.ssrProps = {};
|
|
33
|
+
}
|
|
34
|
+
const { customElements, ssrProps } = metadata;
|
|
31
35
|
// Gather all the SSRable custom elements (ie: root components) into 1 list
|
|
32
36
|
const ssrModules = [];
|
|
33
37
|
for (const [index, { tagName, location, props }] of customElements.entries()) {
|
|
@@ -51,7 +55,6 @@ export default function lwcSsrViewTransformer(options, { moduleBundler, resource
|
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
// SSR and gather the properties and links for each eligible custom element, in parallel
|
|
54
|
-
const ssrProps = {};
|
|
55
58
|
let ssrLinks = '';
|
|
56
59
|
let pageTtl;
|
|
57
60
|
await Promise.all(ssrModules.map(({ index, specifier, tagName, props: rawProps = {}, startOffset, endOffset }) => {
|
|
@@ -96,11 +99,6 @@ export default function lwcSsrViewTransformer(options, { moduleBundler, resource
|
|
|
96
99
|
logger.warn(`Server-side rendering for "${specifier}" failed. Falling back to client-side rendering. Reason: `, err.stack);
|
|
97
100
|
});
|
|
98
101
|
}));
|
|
99
|
-
if (Object.keys(ssrProps).length) {
|
|
100
|
-
// Serialize all root component properties into a single script for the page
|
|
101
|
-
// Append the script before the custom elements; it MUST appear before the AMD shim to avoid timing issues
|
|
102
|
-
stringBuilder.prependLeft(ssrModules[0].startOffset, `<script type="application/javascript">globalThis.LWR = globalThis.LWR || {};globalThis.LWR.${SSR_PROPS_KEY} = ${JSON.stringify(ssrProps)};</script>`);
|
|
103
|
-
}
|
|
104
102
|
if (ssrLinks) {
|
|
105
103
|
// Add all the links to the <head> section of the base document
|
|
106
104
|
const headIndex = stringBuilder.original.indexOf('</head>');
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.10.
|
|
7
|
+
"version": "0.10.4",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@locker/near-membrane-node": "^0.12.15",
|
|
37
|
-
"@lwrjs/diagnostics": "0.10.
|
|
38
|
-
"@lwrjs/instrumentation": "0.10.
|
|
39
|
-
"@lwrjs/shared-utils": "0.10.
|
|
37
|
+
"@lwrjs/diagnostics": "0.10.4",
|
|
38
|
+
"@lwrjs/instrumentation": "0.10.4",
|
|
39
|
+
"@lwrjs/shared-utils": "0.10.4",
|
|
40
40
|
"node-fetch": "^2.6.8"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@lwrjs/types": "0.10.
|
|
43
|
+
"@lwrjs/types": "0.10.4"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=16.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "b945f7642573141e5bda5ba4cb0dc3c622de907d"
|
|
49
49
|
}
|