@lwrjs/client-modules 0.17.2-alpha.4 → 0.17.2-alpha.5
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BOOTSTRAP_END as e,INIT as
|
|
1
|
+
import{BOOTSTRAP_END as e,INIT as o,INIT_MODULE as r}from"lwr/metrics";import{logOperationStart as i,logOperationEnd as t}from"lwr/profiler";import{hydrateComponent as n,createElement as c}from"lwc";function s(e,o,r){n(e,o,r)}const d=(()=>{if(!globalThis.performance)return()=>!1;let e=globalThis.performance.now();return()=>{const o=globalThis.performance.now();return o-e>50&&(e=o,!0)}})();function l(e,o){return c(e,{is:o})}function a(e){return e.replace(/\/v\/[a-zA-Z0-9-_.]+$/,"").replace("/","-").replace(/([A-Z])/g,(e=>`-${e.toLowerCase()}`))}const p=/-([a-z])/g;function f(e){return e.replace(p,(e=>e[1].toUpperCase()))}function u(n,c={}){if(void 0===globalThis.customElements||void 0===globalThis.document)return void i({id:e});i({id:o});let p=0;const u=globalThis.document;for(const[e,o]of n){const n=a(e);if(!u.body.querySelector(n)){i({id:r,specifier:e,specifierIndex:++p});const c=l(n,o),s=u.querySelector("[lwr-root]");s?s.appendChild(c):u.body.appendChild(c),t({id:r,specifier:e,specifierIndex:p,metadata:{renderMode:"spa"}});continue}const m=u.querySelectorAll(n);for(const a of m){i({id:r,specifier:e,specifierIndex:++p});const u=a.dataset.lwrPropsId;if(u){d()&&void 0!==globalThis.setTimeout?globalThis.setTimeout((()=>{s(a,o,c[u]||{})}),0):s(a,o,c[u]||{}),t({id:r,specifier:e,specifierIndex:p,metadata:{renderMode:"ssr"}});continue}const m=l(n,o);for(const{name:e,value:o}of a.attributes){m.setAttribute(e,o);const r=f(e);r in m&&(m[r]=o)}for(;a.childNodes.length>0;)m.appendChild(a.childNodes[0]);const h=a.parentElement;h&&h.replaceChild(m,a),t({id:r,specifier:e,specifierIndex:p,metadata:{renderMode:"csr"}})}}t({id:o}),i({id:e})}export{f as getPropFromAttrName,u as init,a as toKebabCase};
|
|
2
2
|
//# sourceMappingURL=init.js.map
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
import { BOOTSTRAP_END, INIT, INIT_MODULE } from 'lwr/metrics';
|
|
2
2
|
import { logOperationStart, logOperationEnd } from 'lwr/profiler';
|
|
3
3
|
// TODO: This is a temporal workaround until https://github.com/salesforce/lwc/pull/2083 is sorted - tmp
|
|
4
|
+
// eslint-disable-next-line lwr/only-allowed-imports
|
|
4
5
|
import { createElement } from 'lwc';
|
|
5
6
|
// <hydrateComponentProxy> - This code is removed in core
|
|
6
7
|
// Note: a build step uses these comments to strip the code for core.
|
|
8
|
+
// eslint-disable-next-line lwr/only-allowed-imports
|
|
7
9
|
import { hydrateComponent } from 'lwc';
|
|
8
10
|
function hydrateComponentProxy(customElement, Ctor, props) {
|
|
9
11
|
hydrateComponent(customElement, Ctor, props);
|
|
10
12
|
}
|
|
11
13
|
// </hydrateComponentProxy>
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function shouldYield() {
|
|
17
|
-
const now = performance.now();
|
|
18
|
-
if (now - timeOfLastYield > HYDRATION_TASK_BATCH_DURATION) {
|
|
19
|
-
timeOfLastYield = now;
|
|
20
|
-
return true;
|
|
14
|
+
const shouldYield = (() => {
|
|
15
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
16
|
+
if (!globalThis.performance) {
|
|
17
|
+
return () => false;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
// Break up hydration tasks into timed batches.
|
|
20
|
+
// Borrowed from https://tinyurl.com/5b4fw7eb
|
|
21
|
+
const HYDRATION_TASK_BATCH_DURATION = 50;
|
|
22
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
23
|
+
let timeOfLastYield = globalThis.performance.now();
|
|
24
|
+
return () => {
|
|
25
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
26
|
+
const now = globalThis.performance.now();
|
|
27
|
+
if (now - timeOfLastYield > HYDRATION_TASK_BATCH_DURATION) {
|
|
28
|
+
timeOfLastYield = now;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
24
34
|
function initializeWebComponent(elementName, Ctor) {
|
|
25
35
|
return createElement(elementName, { is: Ctor });
|
|
26
36
|
}
|
|
@@ -56,20 +66,26 @@ export function getPropFromAttrName(propName) {
|
|
|
56
66
|
* @example - [['x/appRoot', appCtor], ['x/nav', navCtor]]
|
|
57
67
|
*/
|
|
58
68
|
export function init(rootModules, serverData = {}) {
|
|
59
|
-
|
|
69
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
70
|
+
if (typeof globalThis.customElements === 'undefined' || typeof globalThis.document === 'undefined') {
|
|
60
71
|
logOperationStart({ id: BOOTSTRAP_END });
|
|
61
72
|
return;
|
|
62
73
|
}
|
|
63
74
|
logOperationStart({ id: INIT });
|
|
64
75
|
let index = 0;
|
|
76
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
77
|
+
const document = globalThis.document;
|
|
65
78
|
for (const [specifier, ctor] of rootModules) {
|
|
66
79
|
const elementName = toKebabCase(specifier);
|
|
67
80
|
// initialize and inject the root module into the LWR Root or DOM if it is missing
|
|
81
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
68
82
|
if (!document.body.querySelector(elementName)) {
|
|
69
83
|
logOperationStart({ id: INIT_MODULE, specifier, specifierIndex: ++index });
|
|
70
84
|
// this is for SPA like routes (one component at the root level) utilizing the lwr-root directive
|
|
71
85
|
const component = initializeWebComponent(elementName, ctor);
|
|
86
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
72
87
|
const container = document.querySelector('[lwr-root]');
|
|
88
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
73
89
|
container ? container.appendChild(component) : document.body.appendChild(component);
|
|
74
90
|
logOperationEnd({
|
|
75
91
|
id: INIT_MODULE,
|
|
@@ -80,15 +96,18 @@ export function init(rootModules, serverData = {}) {
|
|
|
80
96
|
continue;
|
|
81
97
|
}
|
|
82
98
|
// the page has been rendered or SSR'd, and each component needs to initialized(or hydrated)
|
|
99
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
83
100
|
const elements = document.querySelectorAll(elementName);
|
|
84
101
|
for (const element of elements) {
|
|
85
102
|
logOperationStart({ id: INIT_MODULE, specifier, specifierIndex: ++index });
|
|
86
103
|
const propsId = element.dataset.lwrPropsId;
|
|
87
104
|
// hydrate SSR'd components
|
|
88
105
|
if (propsId) {
|
|
89
|
-
|
|
106
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
107
|
+
if (shouldYield() && globalThis.setTimeout !== undefined) {
|
|
90
108
|
// give room for the browser to render during long hydration tasks
|
|
91
|
-
|
|
109
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
110
|
+
globalThis.setTimeout(() => {
|
|
92
111
|
hydrateComponentProxy(element, ctor, serverData[propsId] || {});
|
|
93
112
|
}, 0);
|
|
94
113
|
}
|
|
@@ -10,6 +10,7 @@ export function attachDispatcher(dispatcher) {
|
|
|
10
10
|
}
|
|
11
11
|
// Check if the Performance API is available
|
|
12
12
|
// e.g. JSDom (used in Jest) doesn't implement these
|
|
13
|
+
// eslint-disable-next-line
|
|
13
14
|
const perf = globalThis.performance;
|
|
14
15
|
const isPerfSupported = typeof perf !== 'undefined' &&
|
|
15
16
|
typeof perf.mark === 'function' &&
|
|
@@ -1,29 +1,42 @@
|
|
|
1
|
+
// eslint-disable-next-line lwr/only-allowed-type-imports
|
|
2
|
+
|
|
1
3
|
import { BOOTSTRAP_END, INIT, INIT_MODULE } from 'lwr/metrics';
|
|
2
4
|
import { logOperationStart, logOperationEnd } from 'lwr/profiler';
|
|
3
5
|
|
|
4
6
|
// TODO: This is a temporal workaround until https://github.com/salesforce/lwc/pull/2083 is sorted - tmp
|
|
7
|
+
// eslint-disable-next-line lwr/only-allowed-imports
|
|
5
8
|
import { createElement } from 'lwc';
|
|
6
9
|
|
|
7
10
|
// <hydrateComponentProxy> - This code is removed in core
|
|
8
11
|
// Note: a build step uses these comments to strip the code for core.
|
|
12
|
+
// eslint-disable-next-line lwr/only-allowed-imports
|
|
9
13
|
import { hydrateComponent } from 'lwc';
|
|
10
14
|
function hydrateComponentProxy(customElement, Ctor, props) {
|
|
11
15
|
hydrateComponent(customElement, Ctor, props);
|
|
12
16
|
}
|
|
13
17
|
// </hydrateComponentProxy>
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function shouldYield() {
|
|
20
|
-
const now = performance.now();
|
|
21
|
-
if (now - timeOfLastYield > HYDRATION_TASK_BATCH_DURATION) {
|
|
22
|
-
timeOfLastYield = now;
|
|
23
|
-
return true;
|
|
19
|
+
const shouldYield = (() => {
|
|
20
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
21
|
+
if (!globalThis.performance) {
|
|
22
|
+
return () => false;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
|
|
25
|
+
// Break up hydration tasks into timed batches.
|
|
26
|
+
// Borrowed from https://tinyurl.com/5b4fw7eb
|
|
27
|
+
const HYDRATION_TASK_BATCH_DURATION = 50;
|
|
28
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
29
|
+
let timeOfLastYield = globalThis.performance.now();
|
|
30
|
+
return () => {
|
|
31
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
32
|
+
const now = globalThis.performance.now();
|
|
33
|
+
if (now - timeOfLastYield > HYDRATION_TASK_BATCH_DURATION) {
|
|
34
|
+
timeOfLastYield = now;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
27
40
|
function initializeWebComponent(elementName, Ctor) {
|
|
28
41
|
return createElement(elementName, {
|
|
29
42
|
is: Ctor
|
|
@@ -61,7 +74,8 @@ export function getPropFromAttrName(propName) {
|
|
|
61
74
|
* @example - [['x/appRoot', appCtor], ['x/nav', navCtor]]
|
|
62
75
|
*/
|
|
63
76
|
export function init(rootModules, serverData = {}) {
|
|
64
|
-
|
|
77
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
78
|
+
if (typeof globalThis.customElements === 'undefined' || typeof globalThis.document === 'undefined') {
|
|
65
79
|
logOperationStart({
|
|
66
80
|
id: BOOTSTRAP_END
|
|
67
81
|
});
|
|
@@ -71,10 +85,13 @@ export function init(rootModules, serverData = {}) {
|
|
|
71
85
|
id: INIT
|
|
72
86
|
});
|
|
73
87
|
let index = 0;
|
|
88
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
89
|
+
const document = globalThis.document;
|
|
74
90
|
for (const [specifier, ctor] of rootModules) {
|
|
75
91
|
const elementName = toKebabCase(specifier);
|
|
76
92
|
|
|
77
93
|
// initialize and inject the root module into the LWR Root or DOM if it is missing
|
|
94
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
78
95
|
if (!document.body.querySelector(elementName)) {
|
|
79
96
|
logOperationStart({
|
|
80
97
|
id: INIT_MODULE,
|
|
@@ -84,7 +101,9 @@ export function init(rootModules, serverData = {}) {
|
|
|
84
101
|
|
|
85
102
|
// this is for SPA like routes (one component at the root level) utilizing the lwr-root directive
|
|
86
103
|
const component = initializeWebComponent(elementName, ctor);
|
|
104
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
87
105
|
const container = document.querySelector('[lwr-root]');
|
|
106
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
88
107
|
container ? container.appendChild(component) : document.body.appendChild(component);
|
|
89
108
|
logOperationEnd({
|
|
90
109
|
id: INIT_MODULE,
|
|
@@ -98,6 +117,7 @@ export function init(rootModules, serverData = {}) {
|
|
|
98
117
|
}
|
|
99
118
|
|
|
100
119
|
// the page has been rendered or SSR'd, and each component needs to initialized(or hydrated)
|
|
120
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
101
121
|
const elements = document.querySelectorAll(elementName);
|
|
102
122
|
for (const element of elements) {
|
|
103
123
|
logOperationStart({
|
|
@@ -109,9 +129,11 @@ export function init(rootModules, serverData = {}) {
|
|
|
109
129
|
|
|
110
130
|
// hydrate SSR'd components
|
|
111
131
|
if (propsId) {
|
|
112
|
-
|
|
132
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
133
|
+
if (shouldYield() && globalThis.setTimeout !== undefined) {
|
|
113
134
|
// give room for the browser to render during long hydration tasks
|
|
114
|
-
|
|
135
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
136
|
+
globalThis.setTimeout(() => {
|
|
115
137
|
hydrateComponentProxy(element, ctor, serverData[propsId] || {});
|
|
116
138
|
}, 0);
|
|
117
139
|
} else {
|
|
@@ -11,6 +11,7 @@ export function attachDispatcher(dispatcher) {
|
|
|
11
11
|
|
|
12
12
|
// Check if the Performance API is available
|
|
13
13
|
// e.g. JSDom (used in Jest) doesn't implement these
|
|
14
|
+
// eslint-disable-next-line
|
|
14
15
|
const perf = globalThis.performance;
|
|
15
16
|
const isPerfSupported = typeof perf !== 'undefined' && typeof perf.mark === 'function' && typeof perf.clearMarks === 'function' && typeof perf.measure === 'function' && typeof perf.clearMeasures === 'function';
|
|
16
17
|
function getMeasureName(id, specifier) {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.17.2-alpha.
|
|
7
|
+
"version": "0.17.2-alpha.5",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@locker/sandbox": "0.23.6",
|
|
37
|
-
"@lwrjs/shared-utils": "0.17.2-alpha.
|
|
37
|
+
"@lwrjs/shared-utils": "0.17.2-alpha.5"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@lwrjs/types": "0.17.2-alpha.
|
|
40
|
+
"@lwrjs/types": "0.17.2-alpha.5",
|
|
41
41
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
42
42
|
"@rollup/plugin-sucrase": "^5.0.2",
|
|
43
43
|
"@rollup/plugin-terser": "^0.4.4",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"volta": {
|
|
71
71
|
"extends": "../../../package.json"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "b87daf19f22c54126ccaf01e0f899aabe6265885"
|
|
74
74
|
}
|