@lwrjs/client-modules 0.17.2-alpha.6 → 0.17.2-alpha.7
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 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";
|
|
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";const s=(()=>{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 d=/-([a-z])/g;function f(e){return e.replace(d,(e=>e[1].toUpperCase()))}function p(c,d={}){if(void 0===globalThis.customElements||void 0===globalThis.document)return void i({id:e});i({id:o});let p=0;const m=globalThis.document;for(const[e,o]of c){const c=a(e);if(!m.body.querySelector(c)){i({id:r,specifier:e,specifierIndex:++p});const n=l(c,o),s=m.querySelector("[lwr-root]");s?s.appendChild(n):m.body.appendChild(n),t({id:r,specifier:e,specifierIndex:p,metadata:{renderMode:"spa"}});continue}const h=m.querySelectorAll(c);(async()=>{const a=++p;for(const w of h){i({id:r,specifier:e,specifierIndex:a});const h=w.dataset.lwrPropsId;if(h){s()&&await u(),m=w,b=o,g=d[h]||{},n(m,b,g),t({id:r,specifier:e,specifierIndex:p,metadata:{renderMode:"ssr"}});continue}const y=l(c,o);for(const{name:e,value:o}of w.attributes){y.setAttribute(e,o);const r=f(e);r in y&&(y[r]=o)}for(;w.firstChild;)y.appendChild(w.firstChild);w.replaceWith(y),t({id:r,specifier:e,specifierIndex:a,metadata:{renderMode:"csr"}})}var m,b,g})()}t({id:o}),i({id:e})}async function u(){const e=globalThis.scheduler;return function(e){let o,r=e[0],i=1;for(;i<e.length;){const t=e[i],n=e[i+1];if(i+=2,("optionalAccess"===t||"optionalCall"===t)&&null==r)return;"access"===t||"optionalAccess"===t?(o=r,r=n(r)):"call"!==t&&"optionalCall"!==t||(r=n(((...e)=>r.call(o,...e))),o=void 0)}return r}([e,"optionalAccess",e=>e.yield])?e.yield():new Promise((e=>setTimeout(e,0)))}export{f as getPropFromAttrName,p as init,a as toKebabCase};
|
|
2
2
|
//# sourceMappingURL=init.js.map
|
|
@@ -98,61 +98,62 @@ export function init(rootModules, serverData = {}) {
|
|
|
98
98
|
// the page has been rendered or SSR'd, and each component needs to initialized(or hydrated)
|
|
99
99
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
100
100
|
const elements = document.querySelectorAll(elementName);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
101
|
+
(async () => {
|
|
102
|
+
const specifierIndex = ++index;
|
|
103
|
+
for (const element of elements) {
|
|
104
|
+
logOperationStart({ id: INIT_MODULE, specifier, specifierIndex });
|
|
105
|
+
const propsId = element.dataset.lwrPropsId;
|
|
106
|
+
// hydrate SSR'd components
|
|
107
|
+
if (propsId) {
|
|
108
|
+
if (shouldYield()) {
|
|
109
|
+
// Yield to the main thread during long hydration tasks
|
|
110
|
+
// eslint-disable-next-line no-await-in-loop
|
|
111
|
+
await yieldToMainThread();
|
|
112
|
+
}
|
|
115
113
|
hydrateComponentProxy(element, ctor, serverData[propsId] || {});
|
|
114
|
+
logOperationEnd({
|
|
115
|
+
id: INIT_MODULE,
|
|
116
|
+
specifier,
|
|
117
|
+
specifierIndex: index,
|
|
118
|
+
metadata: { renderMode: 'ssr' },
|
|
119
|
+
});
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
// Note: due to the bug described at the top of this file, each CSR'd custom element
|
|
123
|
+
// must be replaced with the new synthetic constructor. Attributes and children are
|
|
124
|
+
// copied over to the new component.
|
|
125
|
+
const component = initializeWebComponent(elementName, ctor);
|
|
126
|
+
// copy the attributes
|
|
127
|
+
for (const { name, value } of element.attributes) {
|
|
128
|
+
component.setAttribute(name, value);
|
|
129
|
+
const prop = getPropFromAttrName(name);
|
|
130
|
+
if (prop in component) {
|
|
131
|
+
// set attributes as properties for reactivity
|
|
132
|
+
component[prop] = value;
|
|
133
|
+
}
|
|
116
134
|
}
|
|
135
|
+
// save the children
|
|
136
|
+
while (element.firstChild) {
|
|
137
|
+
component.appendChild(element.firstChild);
|
|
138
|
+
}
|
|
139
|
+
// swap the element out with the initialized component
|
|
140
|
+
element.replaceWith(component);
|
|
117
141
|
logOperationEnd({
|
|
118
142
|
id: INIT_MODULE,
|
|
119
143
|
specifier,
|
|
120
|
-
specifierIndex
|
|
121
|
-
metadata: { renderMode: '
|
|
144
|
+
specifierIndex,
|
|
145
|
+
metadata: { renderMode: 'csr' },
|
|
122
146
|
});
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
// Note: due to the bug described at the top of this file, each CSR'd custom element
|
|
126
|
-
// must be replaced with the new synthetic constructor. Attributes and children are
|
|
127
|
-
// copied over to the new component.
|
|
128
|
-
const component = initializeWebComponent(elementName, ctor);
|
|
129
|
-
// copy the attributes
|
|
130
|
-
for (const { name, value } of element.attributes) {
|
|
131
|
-
component.setAttribute(name, value);
|
|
132
|
-
const prop = getPropFromAttrName(name);
|
|
133
|
-
if (prop in component) {
|
|
134
|
-
// set attributes as properties for reactivity
|
|
135
|
-
component[prop] = value;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// save the children
|
|
139
|
-
while (element.childNodes.length > 0) {
|
|
140
|
-
component.appendChild(element.childNodes[0]);
|
|
141
|
-
}
|
|
142
|
-
// swap the element out with the initialized component
|
|
143
|
-
const parent = element.parentElement;
|
|
144
|
-
if (parent) {
|
|
145
|
-
parent.replaceChild(component, element);
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
-
id: INIT_MODULE,
|
|
149
|
-
specifier,
|
|
150
|
-
specifierIndex: index,
|
|
151
|
-
metadata: { renderMode: 'csr' },
|
|
152
|
-
});
|
|
153
|
-
}
|
|
148
|
+
})();
|
|
154
149
|
}
|
|
155
150
|
logOperationEnd({ id: INIT });
|
|
156
151
|
logOperationStart({ id: BOOTSTRAP_END });
|
|
157
152
|
}
|
|
153
|
+
// Allows the browser to yield to the main thread during long-running tasks, improving responsiveness.
|
|
154
|
+
async function yieldToMainThread() {
|
|
155
|
+
const scheduler = globalThis.scheduler;
|
|
156
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
157
|
+
return scheduler?.yield ? scheduler.yield() : new Promise((resolve) => setTimeout(resolve, 0));
|
|
158
|
+
}
|
|
158
159
|
//# sourceMappingURL=init.js.map
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// eslint-disable-next-line lwr/only-allowed-type-imports
|
|
2
2
|
|
|
3
|
+
// eslint-disable-next-line lwr/only-allowed-type-imports
|
|
4
|
+
|
|
3
5
|
import { BOOTSTRAP_END, INIT, INIT_MODULE } from 'lwr/metrics';
|
|
4
6
|
import { logOperationStart, logOperationEnd } from 'lwr/profiler';
|
|
5
7
|
|
|
@@ -119,74 +121,70 @@ export function init(rootModules, serverData = {}) {
|
|
|
119
121
|
// the page has been rendered or SSR'd, and each component needs to initialized(or hydrated)
|
|
120
122
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
121
123
|
const elements = document.querySelectorAll(elementName);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
124
|
+
(async () => {
|
|
125
|
+
const specifierIndex = ++index;
|
|
126
|
+
for (const element of elements) {
|
|
127
|
+
logOperationStart({
|
|
128
|
+
id: INIT_MODULE,
|
|
129
|
+
specifier,
|
|
130
|
+
specifierIndex
|
|
131
|
+
});
|
|
132
|
+
const propsId = element.dataset.lwrPropsId;
|
|
133
|
+
|
|
134
|
+
// hydrate SSR'd components
|
|
135
|
+
if (propsId) {
|
|
136
|
+
if (shouldYield()) {
|
|
137
|
+
// Yield to the main thread during long hydration tasks
|
|
138
|
+
// eslint-disable-next-line no-await-in-loop
|
|
139
|
+
await yieldToMainThread();
|
|
140
|
+
}
|
|
140
141
|
hydrateComponentProxy(element, ctor, serverData[propsId] || {});
|
|
142
|
+
logOperationEnd({
|
|
143
|
+
id: INIT_MODULE,
|
|
144
|
+
specifier,
|
|
145
|
+
specifierIndex: index,
|
|
146
|
+
metadata: {
|
|
147
|
+
renderMode: 'ssr'
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
continue;
|
|
141
151
|
}
|
|
152
|
+
|
|
153
|
+
// Note: due to the bug described at the top of this file, each CSR'd custom element
|
|
154
|
+
// must be replaced with the new synthetic constructor. Attributes and children are
|
|
155
|
+
// copied over to the new component.
|
|
156
|
+
const component = initializeWebComponent(elementName, ctor);
|
|
157
|
+
|
|
158
|
+
// copy the attributes
|
|
159
|
+
for (const {
|
|
160
|
+
name,
|
|
161
|
+
value
|
|
162
|
+
} of element.attributes) {
|
|
163
|
+
component.setAttribute(name, value);
|
|
164
|
+
const prop = getPropFromAttrName(name);
|
|
165
|
+
if (prop in component) {
|
|
166
|
+
// set attributes as properties for reactivity
|
|
167
|
+
component[prop] = value;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// save the children
|
|
172
|
+
while (element.firstChild) {
|
|
173
|
+
component.appendChild(element.firstChild);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// swap the element out with the initialized component
|
|
177
|
+
element.replaceWith(component);
|
|
142
178
|
logOperationEnd({
|
|
143
179
|
id: INIT_MODULE,
|
|
144
180
|
specifier,
|
|
145
|
-
specifierIndex
|
|
181
|
+
specifierIndex,
|
|
146
182
|
metadata: {
|
|
147
|
-
renderMode: '
|
|
183
|
+
renderMode: 'csr'
|
|
148
184
|
}
|
|
149
185
|
});
|
|
150
|
-
continue;
|
|
151
186
|
}
|
|
152
|
-
|
|
153
|
-
// Note: due to the bug described at the top of this file, each CSR'd custom element
|
|
154
|
-
// must be replaced with the new synthetic constructor. Attributes and children are
|
|
155
|
-
// copied over to the new component.
|
|
156
|
-
const component = initializeWebComponent(elementName, ctor);
|
|
157
|
-
|
|
158
|
-
// copy the attributes
|
|
159
|
-
for (const {
|
|
160
|
-
name,
|
|
161
|
-
value
|
|
162
|
-
} of element.attributes) {
|
|
163
|
-
component.setAttribute(name, value);
|
|
164
|
-
const prop = getPropFromAttrName(name);
|
|
165
|
-
if (prop in component) {
|
|
166
|
-
// set attributes as properties for reactivity
|
|
167
|
-
component[prop] = value;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// save the children
|
|
172
|
-
while (element.childNodes.length > 0) {
|
|
173
|
-
component.appendChild(element.childNodes[0]);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// swap the element out with the initialized component
|
|
177
|
-
const parent = element.parentElement;
|
|
178
|
-
if (parent) {
|
|
179
|
-
parent.replaceChild(component, element);
|
|
180
|
-
}
|
|
181
|
-
logOperationEnd({
|
|
182
|
-
id: INIT_MODULE,
|
|
183
|
-
specifier,
|
|
184
|
-
specifierIndex: index,
|
|
185
|
-
metadata: {
|
|
186
|
-
renderMode: 'csr'
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
187
|
+
})();
|
|
190
188
|
}
|
|
191
189
|
logOperationEnd({
|
|
192
190
|
id: INIT
|
|
@@ -194,4 +192,11 @@ export function init(rootModules, serverData = {}) {
|
|
|
194
192
|
logOperationStart({
|
|
195
193
|
id: BOOTSTRAP_END
|
|
196
194
|
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Allows the browser to yield to the main thread during long-running tasks, improving responsiveness.
|
|
198
|
+
async function yieldToMainThread() {
|
|
199
|
+
const scheduler = globalThis.scheduler;
|
|
200
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
201
|
+
return scheduler?.yield ? scheduler.yield() : new Promise(resolve => setTimeout(resolve, 0));
|
|
197
202
|
}
|
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.7",
|
|
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.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@lwrjs/types": "0.17.2-alpha.
|
|
40
|
+
"@lwrjs/types": "0.17.2-alpha.7",
|
|
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": "13d2ef766b72903be7be11a0ddc4704fe649f77a"
|
|
74
74
|
}
|