@lwrjs/client-modules 0.17.2-alpha.1 → 0.17.2-alpha.2

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 r,INIT_MODULE as t}from"lwr/metrics";import{logOperationStart as o,logOperationEnd as i}from"lwr/profiler";import{hydrateComponent as n,createElement as d}from"lwc";function c(e,r){return d(e,{is:r})}function s(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 a(d,p={}){if("undefined"==typeof customElements||"undefined"==typeof document)return void o({id:e});o({id:r});let a=0;for(const[e,r]of d){const d=s(e);if(!document.body.querySelector(d)){o({id:t,specifier:e,specifierIndex:++a});const n=c(d,r),s=document.querySelector("[lwr-root]");s?s.appendChild(n):document.body.appendChild(n),i({id:t,specifier:e,specifierIndex:a,metadata:{renderMode:"spa"}});continue}const h=document.querySelectorAll(d);for(const s of h){o({id:t,specifier:e,specifierIndex:++a});const h=s.dataset.lwrPropsId;if(h){l=s,u=r,m=p[h]||{},n(l,u,m),i({id:t,specifier:e,specifierIndex:a,metadata:{renderMode:"ssr"}});continue}const y=c(d,r);for(const{name:e,value:r}of s.attributes){y.setAttribute(e,r);const t=f(e);t in y&&(y[t]=r)}for(;s.childNodes.length>0;)y.appendChild(s.childNodes[0]);const w=s.parentElement;w&&w.replaceChild(y,s),i({id:t,specifier:e,specifierIndex:a,metadata:{renderMode:"csr"}})}}var l,u,m;i({id:r}),o({id:e})}export{f as getPropFromAttrName,a as init,s as toKebabCase};
1
+ import{BOOTSTRAP_END as e,INIT as r,INIT_MODULE as t}from"lwr/metrics";import{logOperationStart as o,logOperationEnd as n}from"lwr/profiler";import{hydrateComponent as i,createElement as c}from"lwc";function d(e,r,t){i(e,r,t)}const s=50;let f=performance.now();function p(){const e=performance.now();return e-f>s&&(f=e,!0)}function a(e,r){return c(e,{is:r})}function l(e){return e.replace(/\/v\/[a-zA-Z0-9-_.]+$/,"").replace("/","-").replace(/([A-Z])/g,(e=>`-${e.toLowerCase()}`))}const u=/-([a-z])/g;function m(e){return e.replace(u,(e=>e[1].toUpperCase()))}function w(i,c={}){if("undefined"==typeof customElements||"undefined"==typeof document)return void o({id:e});o({id:r});let s=0;for(const[e,r]of i){const i=l(e);if(!document.body.querySelector(i)){o({id:t,specifier:e,specifierIndex:++s});const c=a(i,r),d=document.querySelector("[lwr-root]");d?d.appendChild(c):document.body.appendChild(c),n({id:t,specifier:e,specifierIndex:s,metadata:{renderMode:"spa"}});continue}const f=document.querySelectorAll(i);for(const l of f){o({id:t,specifier:e,specifierIndex:++s});const f=l.dataset.lwrPropsId;if(f){p()?setTimeout((()=>{d(l,r,c[f]||{})}),0):d(l,r,c[f]||{}),n({id:t,specifier:e,specifierIndex:s,metadata:{renderMode:"ssr"}});continue}const u=a(i,r);for(const{name:e,value:r}of l.attributes){u.setAttribute(e,r);const t=m(e);t in u&&(u[t]=r)}for(;l.childNodes.length>0;)u.appendChild(l.childNodes[0]);const w=l.parentElement;w&&w.replaceChild(u,l),n({id:t,specifier:e,specifierIndex:s,metadata:{renderMode:"csr"}})}}n({id:r}),o({id:e})}export{m as getPropFromAttrName,w as init,l as toKebabCase};
2
2
  //# sourceMappingURL=init.js.map
@@ -3,11 +3,24 @@ 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
4
  import { createElement } from 'lwc';
5
5
  // <hydrateComponentProxy> - This code is removed in core
6
+ // Note: a build step uses these comments to strip the code for core.
6
7
  import { hydrateComponent } from 'lwc';
7
8
  function hydrateComponentProxy(customElement, Ctor, props) {
8
9
  hydrateComponent(customElement, Ctor, props);
9
10
  }
10
11
  // </hydrateComponentProxy>
12
+ // Break up hydration tasks into timed batches.
13
+ // Borrowed from https://tinyurl.com/5b4fw7eb
14
+ const HYDRATION_TASK_BATCH_DURATION = 50;
15
+ let timeOfLastYield = performance.now();
16
+ function shouldYield() {
17
+ const now = performance.now();
18
+ if (now - timeOfLastYield > HYDRATION_TASK_BATCH_DURATION) {
19
+ timeOfLastYield = now;
20
+ return true;
21
+ }
22
+ return false;
23
+ }
11
24
  function initializeWebComponent(elementName, Ctor) {
12
25
  return createElement(elementName, { is: Ctor });
13
26
  }
@@ -73,7 +86,15 @@ export function init(rootModules, serverData = {}) {
73
86
  const propsId = element.dataset.lwrPropsId;
74
87
  // hydrate SSR'd components
75
88
  if (propsId) {
76
- hydrateComponentProxy(element, ctor, serverData[propsId] || {});
89
+ if (shouldYield()) {
90
+ // give room for the browser to render during long hydration tasks
91
+ setTimeout(() => {
92
+ hydrateComponentProxy(element, ctor, serverData[propsId] || {});
93
+ }, 0);
94
+ }
95
+ else {
96
+ hydrateComponentProxy(element, ctor, serverData[propsId] || {});
97
+ }
77
98
  logOperationEnd({
78
99
  id: INIT_MODULE,
79
100
  specifier,
@@ -5,12 +5,25 @@ import { logOperationStart, logOperationEnd } from 'lwr/profiler';
5
5
  import { createElement } from 'lwc';
6
6
 
7
7
  // <hydrateComponentProxy> - This code is removed in core
8
+ // Note: a build step uses these comments to strip the code for core.
8
9
  import { hydrateComponent } from 'lwc';
9
10
  function hydrateComponentProxy(customElement, Ctor, props) {
10
11
  hydrateComponent(customElement, Ctor, props);
11
12
  }
12
13
  // </hydrateComponentProxy>
13
14
 
15
+ // Break up hydration tasks into timed batches.
16
+ // Borrowed from https://tinyurl.com/5b4fw7eb
17
+ const HYDRATION_TASK_BATCH_DURATION = 50;
18
+ let timeOfLastYield = performance.now();
19
+ function shouldYield() {
20
+ const now = performance.now();
21
+ if (now - timeOfLastYield > HYDRATION_TASK_BATCH_DURATION) {
22
+ timeOfLastYield = now;
23
+ return true;
24
+ }
25
+ return false;
26
+ }
14
27
  function initializeWebComponent(elementName, Ctor) {
15
28
  return createElement(elementName, {
16
29
  is: Ctor
@@ -96,7 +109,14 @@ export function init(rootModules, serverData = {}) {
96
109
 
97
110
  // hydrate SSR'd components
98
111
  if (propsId) {
99
- hydrateComponentProxy(element, ctor, serverData[propsId] || {});
112
+ if (shouldYield()) {
113
+ // give room for the browser to render during long hydration tasks
114
+ setTimeout(() => {
115
+ hydrateComponentProxy(element, ctor, serverData[propsId] || {});
116
+ }, 0);
117
+ } else {
118
+ hydrateComponentProxy(element, ctor, serverData[propsId] || {});
119
+ }
100
120
  logOperationEnd({
101
121
  id: INIT_MODULE,
102
122
  specifier,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.2-alpha.1",
7
+ "version": "0.17.2-alpha.2",
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.1"
37
+ "@lwrjs/shared-utils": "0.17.2-alpha.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@lwrjs/types": "0.17.2-alpha.1",
40
+ "@lwrjs/types": "0.17.2-alpha.2",
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": "bba15ca717a242b0375decaa378af06bdee813b5"
73
+ "gitHead": "739b237f5d7f2c1989142cb505a56cc763f21976"
74
74
  }