@lwrjs/client-modules 0.17.2-alpha.4 → 0.17.2-alpha.6

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 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};
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
- // 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;
14
+ const shouldYield = (() => {
15
+ // eslint-disable-next-line lwr/no-unguarded-apis
16
+ if (!globalThis.performance) {
17
+ return () => false;
21
18
  }
22
- return false;
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
- if (typeof customElements === 'undefined' || typeof document === 'undefined') {
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
- if (shouldYield()) {
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
- setTimeout(() => {
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
- // 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;
19
+ const shouldYield = (() => {
20
+ // eslint-disable-next-line lwr/no-unguarded-apis
21
+ if (!globalThis.performance) {
22
+ return () => false;
24
23
  }
25
- return false;
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
- if (typeof customElements === 'undefined' || typeof document === 'undefined') {
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
- if (shouldYield()) {
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
- setTimeout(() => {
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.4",
7
+ "version": "0.17.2-alpha.6",
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.4"
37
+ "@lwrjs/shared-utils": "0.17.2-alpha.6"
38
38
  },
39
39
  "devDependencies": {
40
- "@lwrjs/types": "0.17.2-alpha.4",
40
+ "@lwrjs/types": "0.17.2-alpha.6",
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": "d7fb1605cec0bf9fef18e3daeb17dc28b35a80d3"
73
+ "gitHead": "e52a06333b7cd8d6d4bdc846ea9019d13f9fb85d"
74
74
  }