@lynx-js/web-worker-runtime 0.17.1 → 0.18.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # @lynx-js/web-worker-runtime
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: ([#1837](https://github.com/lynx-family/lynx-stack/pull/1837))
8
+
9
+ 1. `LynxView.updateData()` cannot trigger `dataProcessor`.
10
+
11
+ 2. **This is a break change:** The second parameter of `LynxView.updateData()` has been changed from `UpdateDataType` to `string`, which is the `processorName` (default is `default` which will use `defaultDataProcessor`). This change is to better align with Native. The current complete type is as follows:
12
+
13
+ ```ts
14
+ LynxView.updateData(data: Cloneable, processorName?: string | undefined, callback?: (() => void) | undefined): void
15
+ ```
16
+
17
+ - Updated dependencies [[`77397fd`](https://github.com/lynx-family/lynx-stack/commit/77397fd535cf60556f8f82f7ef8dae8a623d1625), [`7d90ed5`](https://github.com/lynx-family/lynx-stack/commit/7d90ed52a20fd7665a3517507800e7e29426f6f9)]:
18
+ - @lynx-js/web-constants@0.18.0
19
+ - @lynx-js/web-mainthread-apis@0.18.0
20
+ - @lynx-js/web-worker-rpc@0.18.0
21
+
22
+ ## 0.17.2
23
+
24
+ ### Patch Changes
25
+
26
+ - feat: support load bts chunk from remote address ([#1834](https://github.com/lynx-family/lynx-stack/pull/1834))
27
+
28
+ - re-support chunk splitting
29
+ - support lynx.requireModule with a json file
30
+ - support lynx.requireModule, lynx.requireModuleAsync with a remote url
31
+ - support to add a breakpoint in chrome after reloading the web page
32
+
33
+ - Updated dependencies [[`a35a245`](https://github.com/lynx-family/lynx-stack/commit/a35a2452e5355bda3c475f9a750a86085e0cf56a)]:
34
+ - @lynx-js/web-constants@0.17.2
35
+ - @lynx-js/web-mainthread-apis@0.17.2
36
+ - @lynx-js/web-worker-rpc@0.17.2
37
+
3
38
  ## 0.17.1
4
39
 
5
40
  ### Patch Changes
@@ -0,0 +1,7 @@
1
+ import type { NativeApp, LynxTemplate } from '@lynx-js/web-constants';
2
+ export declare function createChunkLoading(initialTemplate: LynxTemplate): {
3
+ readScript: NativeApp['readScript'];
4
+ loadScript: NativeApp['loadScript'];
5
+ loadScriptAsync: NativeApp['loadScriptAsync'];
6
+ templateCache: Map<string, LynxTemplate>;
7
+ };
@@ -0,0 +1,73 @@
1
+ // Copyright 2023 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ export function createChunkLoading(initialTemplate) {
5
+ const templateCache = new Map([[
6
+ '__Card__',
7
+ initialTemplate,
8
+ ]]);
9
+ const readScript = (sourceURL, entryName = '__Card__') => {
10
+ const jsContentInTemplate = templateCache.get(entryName)
11
+ ?.manifest[`/${sourceURL}`];
12
+ if (jsContentInTemplate)
13
+ return jsContentInTemplate;
14
+ const xhr = new XMLHttpRequest();
15
+ xhr.open('GET', sourceURL, false);
16
+ xhr.send(null);
17
+ if (xhr.status === 200) {
18
+ return xhr.responseText;
19
+ }
20
+ throw new Error(`Failed to load ${sourceURL}, status: ${xhr.status}`);
21
+ };
22
+ const readScriptAsync = async (sourceURL, entryName = '__Card__') => {
23
+ const jsContentInTemplate = templateCache.get(entryName)
24
+ ?.manifest[`/${sourceURL}`];
25
+ if (jsContentInTemplate)
26
+ return jsContentInTemplate;
27
+ return new Promise((resolve, reject) => {
28
+ fetch(sourceURL).then((response) => {
29
+ if (response.ok) {
30
+ response.text().then((text) => resolve(text), reject);
31
+ }
32
+ else {
33
+ reject(new Error(`Failed to load ${sourceURL}, status: ${response.status}`));
34
+ }
35
+ }, reject);
36
+ });
37
+ };
38
+ const createBundleInitReturnObj = (jsContent, fileName) => {
39
+ const foo = new Function('postMessage', 'module', 'exports', 'lynxCoreInject', 'Card', 'setTimeout', 'setInterval', 'clearInterval', 'clearTimeout', 'NativeModules', 'Component', 'ReactLynx', 'nativeAppId', 'Behavior', 'LynxJSBI', 'lynx',
40
+ // BOM API
41
+ 'window', 'document', 'frames', 'location', 'navigator', 'localStorage', 'history', 'Caches', 'screen', 'alert', 'confirm', 'prompt', 'fetch', 'XMLHttpRequest', 'webkit', 'Reporter', 'print', 'global',
42
+ // Lynx API
43
+ 'requestAnimationFrame', 'cancelAnimationFrame', [
44
+ jsContent,
45
+ '\n//# sourceURL=',
46
+ fileName,
47
+ ].join(''));
48
+ return {
49
+ init(lynxCoreInject) {
50
+ const module = { exports: {} };
51
+ const tt = lynxCoreInject.tt;
52
+ foo(undefined, module, module.exports, lynxCoreInject, tt.Card, tt.setTimeout, tt.setInterval, tt.clearInterval, tt.clearTimeout, tt.NativeModules, tt.Component, tt.ReactLynx, tt.nativeAppId, tt.Behavior, tt.LynxJSBI, tt.lynx,
53
+ // BOM API
54
+ tt.window, tt.document, tt.frames, tt.location, tt.navigator, tt.localStorage, tt.history, tt.Caches, tt.screen, tt.alert, tt.confirm, tt.prompt, tt.fetch, tt.XMLHttpRequest, tt.webkit, tt.Reporter, tt.print, tt.global, tt.requestAnimationFrame, tt.cancelAnimationFrame);
55
+ return module.exports;
56
+ },
57
+ };
58
+ };
59
+ return {
60
+ readScript,
61
+ loadScript: (sourceURL, entryName = '__Card__') => {
62
+ const jsContent = readScript(sourceURL, entryName);
63
+ return createBundleInitReturnObj(jsContent, `${encodeURIComponent(entryName)}/${sourceURL}`);
64
+ },
65
+ loadScriptAsync: async (sourceURL, callback, entryName = '__Card__') => {
66
+ readScriptAsync(sourceURL, entryName).then((jsContent) => {
67
+ callback(null, createBundleInitReturnObj(jsContent, `${encodeURIComponent(entryName)}/${sourceURL}`));
68
+ });
69
+ },
70
+ templateCache,
71
+ };
72
+ }
73
+ //# sourceMappingURL=createChunkLoading.js.map
@@ -11,6 +11,7 @@ import { createJSObjectDestructionObserver } from './crossThreadHandlers/createJ
11
11
  import { registerUpdateGlobalPropsHandler } from './crossThreadHandlers/registerUpdateGlobalPropsHandler.js';
12
12
  import { registerUpdateI18nResource } from './crossThreadHandlers/registerUpdateI18nResource.js';
13
13
  import { createGetPathInfo } from './crossThreadHandlers/createGetPathInfo.js';
14
+ import { createChunkLoading } from './createChunkLoading.js';
14
15
  let nativeAppCount = 0;
15
16
  const sharedData = {};
16
17
  export async function createNativeApp(config) {
@@ -22,13 +23,7 @@ export async function createNativeApp(config) {
22
23
  const selectComponent = uiThreadRpc.createCallbackify(selectComponentEndpoint, 3);
23
24
  const queryComponent = mainThreadRpc.createCall(queryComponentEndpoint);
24
25
  const reportError = uiThreadRpc.createCall(reportErrorEndpoint);
25
- const createBundleInitReturnObj = () => {
26
- const ret = globalThis.module.exports ?? globalThis.__bundle__holder;
27
- globalThis.module.exports = null;
28
- globalThis.__bundle__holder = null;
29
- return ret;
30
- };
31
- const templateCache = new Map([['__Card__', template]]);
26
+ const { templateCache, loadScript, loadScriptAsync, readScript } = createChunkLoading(template);
32
27
  mainThreadRpc.registerHandler(updateBTSTemplateCacheEndpoint, (url, template) => {
33
28
  templateCache.set(url, template);
34
29
  });
@@ -42,35 +37,9 @@ export async function createNativeApp(config) {
42
37
  clearTimeout: clearTimeout,
43
38
  clearInterval: clearInterval,
44
39
  nativeModuleProxy: await createNativeModules(uiThreadRpc, mainThreadRpc, nativeModulesMap),
45
- loadScriptAsync: function (sourceURL, callback, entryName) {
46
- entryName = entryName ?? '__Card__';
47
- const manifestUrl = templateCache.get(entryName)
48
- ?.manifest[`/${sourceURL}`];
49
- if (manifestUrl)
50
- sourceURL = manifestUrl;
51
- else
52
- throw Error(`Cannot find ${sourceURL} in manifest`);
53
- globalThis.module.exports = null;
54
- globalThis.__bundle__holder = null;
55
- import(
56
- /* webpackIgnore: true */
57
- sourceURL).catch(callback).then(async () => {
58
- callback(null, createBundleInitReturnObj());
59
- });
60
- },
61
- loadScript: (sourceURL, entryName) => {
62
- entryName = entryName ?? '__Card__';
63
- const manifestUrl = templateCache.get(entryName)
64
- ?.manifest[`/${sourceURL}`];
65
- if (manifestUrl)
66
- sourceURL = manifestUrl;
67
- else
68
- throw Error(`Cannot find ${sourceURL} in manifest`);
69
- globalThis.module.exports = null;
70
- globalThis.__bundle__holder = null;
71
- importScripts(sourceURL);
72
- return createBundleInitReturnObj();
73
- },
40
+ readScript,
41
+ loadScriptAsync,
42
+ loadScript,
74
43
  requestAnimationFrame(cb) {
75
44
  return requestAnimationFrame(cb);
76
45
  },
@@ -86,7 +55,7 @@ export async function createNativeApp(config) {
86
55
  registerPublicComponentEventHandler(mainThreadRpc, tt);
87
56
  registerPublishEventHandler(mainThreadRpc, tt);
88
57
  registerGlobalExposureEventHandler(mainThreadRpc, tt);
89
- registerUpdateDataHandler(uiThreadRpc, tt);
58
+ registerUpdateDataHandler(mainThreadRpc, tt);
90
59
  registerSendGlobalEventHandler(uiThreadRpc, tt);
91
60
  registerUpdateGlobalPropsHandler(uiThreadRpc, tt);
92
61
  registerUpdateI18nResource(uiThreadRpc, mainThreadRpc, i18nResource, tt);
@@ -1,3 +1,2 @@
1
- import { type MainThreadGlobalThis } from '@lynx-js/web-constants';
2
1
  import type { Rpc } from '@lynx-js/web-worker-rpc';
3
- export declare function registerUpdateDataHandler(rpc: Rpc, runtime: MainThreadGlobalThis): void;
2
+ export declare function registerUpdateDataHandler(mainThreadRpc: Rpc, handleUpdatedData: ReturnType<typeof import('@lynx-js/web-mainthread-apis').prepareMainThreadAPIs>['handleUpdatedData']): void;
@@ -1,10 +1,8 @@
1
1
  // Copyright 2023 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- import { updateDataEndpoint, } from '@lynx-js/web-constants';
5
- export function registerUpdateDataHandler(rpc, runtime) {
6
- rpc.registerHandler(updateDataEndpoint, (...args) => {
7
- runtime.updatePage?.(...args);
8
- });
4
+ import { updateDataEndpoint } from '@lynx-js/web-constants';
5
+ export function registerUpdateDataHandler(mainThreadRpc, handleUpdatedData) {
6
+ mainThreadRpc.registerHandler(updateDataEndpoint, (newData, options) => handleUpdatedData(newData, options));
9
7
  }
10
8
  //# sourceMappingURL=registerUpdateDataHandler.js.map
@@ -61,7 +61,7 @@ export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort)
61
61
  uiThreadRpc.registerHandler(postOffscreenEventEndpoint, document[_onEvent]);
62
62
  const sendMultiThreadExposureChangedEndpoint = uiThreadRpc.createCall(multiThreadExposureChangedEndpoint);
63
63
  const loadTemplate = uiThreadRpc.createCall(loadTemplateMultiThread);
64
- const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, document, // rootDom
64
+ const { startMainThread, handleUpdatedData } = prepareMainThreadAPIs(backgroundThreadRpc, document, // rootDom
65
65
  document, mtsRealm, (exposureChangedElementUniqueIds) => {
66
66
  document.commit();
67
67
  sendMultiThreadExposureChangedEndpoint(exposureChangedElementUniqueIds
@@ -73,7 +73,7 @@ export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort)
73
73
  }, loadTemplate);
74
74
  uiThreadRpc.registerHandler(mainThreadStartEndpoint, async (config) => {
75
75
  await startMainThread(config);
76
- registerUpdateDataHandler(uiThreadRpc, globalThis);
76
+ registerUpdateDataHandler(uiThreadRpc, handleUpdatedData);
77
77
  });
78
78
  uiThreadRpc.registerHandler(updateI18nResourcesEndpoint, data => {
79
79
  i18nResources.setData(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-worker-runtime",
3
- "version": "0.17.1",
3
+ "version": "0.18.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -23,9 +23,9 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@lynx-js/offscreen-document": "0.1.4",
26
- "@lynx-js/web-constants": "0.17.1",
27
- "@lynx-js/web-mainthread-apis": "0.17.1",
28
- "@lynx-js/web-worker-rpc": "0.17.1"
26
+ "@lynx-js/web-constants": "0.18.0",
27
+ "@lynx-js/web-mainthread-apis": "0.18.0",
28
+ "@lynx-js/web-worker-rpc": "0.18.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@lynx-js/lynx-core": "0.1.3"