@lwrjs/client-modules 0.13.0-alpha.16 → 0.13.0-alpha.18

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,34 +1,43 @@
1
- import { updateStaleModule } from './util/swap';
1
+ import { swapTemplate, swapStyle, swapComponent } from 'lwc';
2
2
 
3
- // This is a workaround until we don't change the way HMR works
4
- // The server will always return the same canonical "latest URL"
5
- // So we need to track the last new URI instead
3
+ // Track the newest URI for each module.
6
4
  const URI_MAPPING = new Map();
7
5
 
8
6
  async function moduleUpdate(payload) {
9
7
  const {
8
+ format,
10
9
  oldUri,
11
10
  newUri,
12
11
  module: { specifier },
13
12
  } = payload;
14
13
 
15
- const lastEvalutedUri = URI_MAPPING.get(oldUri) || oldUri;
16
- const oldModule = await import(lastEvalutedUri);
17
- const newModule = await import(newUri);
18
- URI_MAPPING.set(oldUri, newUri);
14
+ if (format === 'amd') {
15
+ // Need to integrate new LWC APIs to support inline HMR for AMD+CSR
16
+ window.location.reload();
17
+ } else {
18
+ const lastEvalutedUri = URI_MAPPING.get(oldUri) || oldUri;
19
+ const oldModule = await import(lastEvalutedUri);
20
+ const newModule = await import(newUri);
21
+ URI_MAPPING.set(oldUri, newUri);
22
+ updateStaleModule({ oldModule, newModule, specifier });
23
+ }
24
+ }
19
25
 
20
- updateStaleModule({
21
- oldModule,
22
- newModule,
23
- specifier,
24
- });
26
+ function updateStaleModule({ oldModule, newModule, specifier }) {
27
+ if (specifier.endsWith('html') && newModule.default) {
28
+ console.log(`Swapping HTML template for module "${specifier}"`);
29
+ swapTemplate(oldModule.default, newModule.default);
30
+ } else if (specifier.endsWith('css') && newModule.default) {
31
+ console.log(`Swapping CSS for module "${specifier}"`);
32
+ swapStyle(oldModule.default[0], newModule.default[0]);
33
+ } else {
34
+ console.log(`Swapping JS for module "${specifier}"`);
35
+ swapComponent(oldModule.default, newModule.default);
36
+ }
25
37
  }
26
38
 
27
39
  function viewUpdate(payload, metadata) {
28
- const viewId = payload.viewId;
29
- const assetId = payload.assetId;
30
-
31
- // eslint-disable-next-line no-undef
40
+ const { assetId, viewId } = payload;
32
41
  if (metadata.templates.includes(viewId) || metadata.assetReferences.includes(assetId)) {
33
42
  window.location.reload();
34
43
  }
@@ -38,8 +47,8 @@ async function waitForSuccessfulPing(socketUrl) {
38
47
  // eslint-disable-next-line no-constant-condition
39
48
  while (true) {
40
49
  try {
41
- // Fetching for the socket URL reject with a network error if not available. If the dev
42
- // server comes back online, it resolve with 404 HTTP response.
50
+ // Poll for the socket URL; reject with a network error if not available.
51
+ // If the dev server comes back online, it resolves with a 404 HTTP response.
43
52
  await fetch(`http://${socketUrl}`);
44
53
  break;
45
54
  } catch (error) {
@@ -49,19 +58,14 @@ async function waitForSuccessfulPing(socketUrl) {
49
58
  }
50
59
 
51
60
  export function initHMR(serverURI = '', metadata) {
52
- const normalizedMeta = {
53
- ...{ assetReferences: [], templates: [] },
54
- ...metadata,
55
- };
56
-
61
+ const normalizedMeta = { ...{ assetReferences: [], templates: [] }, ...metadata };
57
62
  // {apiVersion}/hmr/{format}/{compat}?debug
58
63
  const host = serverURI.startsWith('/') ? location.host : '';
59
64
  const socketUrl = `${host}${serverURI}`;
60
-
61
65
  const socket = new WebSocket(`ws://${socketUrl}`);
62
66
 
63
67
  socket.addEventListener('close', async (evt) => {
64
- // Don't do anything is the socket close event was initiated by the client.
68
+ // Don't do anything if the socket close event was initiated by the client.
65
69
  if (evt.wasClean) {
66
70
  return;
67
71
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.13.0-alpha.16",
7
+ "version": "0.13.0-alpha.18",
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.22.2",
37
- "@lwrjs/shared-utils": "0.13.0-alpha.16"
37
+ "@lwrjs/shared-utils": "0.13.0-alpha.18"
38
38
  },
39
39
  "devDependencies": {
40
- "@lwrjs/types": "0.13.0-alpha.16",
40
+ "@lwrjs/types": "0.13.0-alpha.18",
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": "5aabb958d70a4a962b207da21e852d7a801d7d44"
73
+ "gitHead": "da3c9ea71a70cc4e81d6e8bc8625ba9d00f784bd"
74
74
  }
@@ -1,12 +0,0 @@
1
- import { swapTemplate, swapStyle, swapComponent } from 'lwc';
2
-
3
- export function updateStaleModule({ oldModule, newModule, specifier }) {
4
- if (specifier.endsWith('html') && newModule.default) {
5
- console.log(`Swapping html template for module "${specifier}"`);
6
- swapTemplate(oldModule.default, newModule.default);
7
- } else if (specifier.endsWith('css') && newModule.default) {
8
- swapStyle(oldModule.default[0], newModule.default[0]);
9
- } else {
10
- swapComponent(oldModule.default, newModule.default);
11
- }
12
- }