@lynx-js/web-core 0.17.2 → 0.18.1

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,43 @@
1
1
  # @lynx-js/web-core
2
2
 
3
+ ## 0.18.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: mts freeze after reload() ([#1892](https://github.com/lynx-family/lynx-stack/pull/1892))
8
+
9
+ The mts may be freezed after reload() called.
10
+
11
+ We fixed it by waiting until the all-on-ui Javascript realm implementation, an iframe, to be fully loaded.
12
+
13
+ - Updated dependencies [[`70a18fc`](https://github.com/lynx-family/lynx-stack/commit/70a18fce0083743e4516eefc91c0392d748b855f)]:
14
+ - @lynx-js/web-mainthread-apis@0.18.1
15
+ - @lynx-js/web-worker-runtime@0.18.1
16
+ - @lynx-js/web-constants@0.18.1
17
+ - @lynx-js/web-worker-rpc@0.18.1
18
+
19
+ ## 0.18.0
20
+
21
+ ### Minor Changes
22
+
23
+ - fix: ([#1837](https://github.com/lynx-family/lynx-stack/pull/1837))
24
+
25
+ 1. `LynxView.updateData()` cannot trigger `dataProcessor`.
26
+
27
+ 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:
28
+
29
+ ```ts
30
+ LynxView.updateData(data: Cloneable, processorName?: string | undefined, callback?: (() => void) | undefined): void
31
+ ```
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies [[`77397fd`](https://github.com/lynx-family/lynx-stack/commit/77397fd535cf60556f8f82f7ef8dae8a623d1625), [`7d90ed5`](https://github.com/lynx-family/lynx-stack/commit/7d90ed52a20fd7665a3517507800e7e29426f6f9)]:
36
+ - @lynx-js/web-worker-runtime@0.18.0
37
+ - @lynx-js/web-constants@0.18.0
38
+ - @lynx-js/web-mainthread-apis@0.18.0
39
+ - @lynx-js/web-worker-rpc@0.18.0
40
+
3
41
  ## 0.17.2
4
42
 
5
43
  ### Patch Changes
@@ -1424,7 +1462,7 @@
1424
1462
  ```
1425
1463
  * @param {string} url [required] The url of the entry of your Lynx card
1426
1464
  * @param {Cloneable} globalProps [optional] The globalProps value of this Lynx card
1427
- * @param {Cloneable} initData [oprional] The initial data of this Lynx card
1465
+ * @param {Cloneable} initData [optional] The initial data of this Lynx card
1428
1466
  * @param {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
1429
1467
  * @param {NativeModulesCallHandler} onNativeModulesCall [optional] the NativeModules.bridge.call value handler. Arguments will be cached before this property is assigned.
1430
1468
  *
@@ -1,4 +1,4 @@
1
- import { type Cloneable, type I18nResourceTranslationOptions, type InitI18nResources, type LynxTemplate, type NapiModulesCall, type NapiModulesMap, type NativeModulesCall, type NativeModulesMap, type UpdateDataType } from '@lynx-js/web-constants';
1
+ import { type Cloneable, type I18nResourceTranslationOptions, type InitI18nResources, type LynxTemplate, type NapiModulesCall, type NapiModulesMap, type NativeModulesCall, type NativeModulesMap } from '@lynx-js/web-constants';
2
2
  export type INapiModulesCall = (name: string, data: any, moduleName: string, lynxView: LynxView, dispatchNapiModules: (data: Cloneable) => void) => Promise<{
3
3
  data: unknown;
4
4
  transfer?: Transferable[];
@@ -12,7 +12,7 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
12
12
  /**
13
13
  * @property {string} url [required] (attribute: "url") The url of the entry of your Lynx card
14
14
  * @property {Cloneable} globalProps [optional] (attribute: "global-props") The globalProps value of this Lynx card
15
- * @property {Cloneable} initData [oprional] (attribute: "init-data") The initial data of this Lynx card
15
+ * @property {Cloneable} initData [optional] (attribute: "init-data") The initial data of this Lynx card
16
16
  * @property {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
17
17
  * @property {NativeModulesMap} nativeModulesMap [optional] use to customize NativeModules. key is module-name, value is esm url.
18
18
  * @property {NativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
@@ -132,7 +132,7 @@ export declare class LynxView extends HTMLElement {
132
132
  * @method
133
133
  * update the `__initData` and trigger essential flow
134
134
  */
135
- updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
135
+ updateData(data: Cloneable, processorName?: string, callback?: () => void): void;
136
136
  /**
137
137
  * @public
138
138
  * @method
@@ -9,7 +9,7 @@ import { inShadowRootStyles, lynxDisposedAttribute, lynxTagAttribute, } from '@l
9
9
  /**
10
10
  * @property {string} url [required] (attribute: "url") The url of the entry of your Lynx card
11
11
  * @property {Cloneable} globalProps [optional] (attribute: "global-props") The globalProps value of this Lynx card
12
- * @property {Cloneable} initData [oprional] (attribute: "init-data") The initial data of this Lynx card
12
+ * @property {Cloneable} initData [optional] (attribute: "init-data") The initial data of this Lynx card
13
13
  * @property {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
14
14
  * @property {NativeModulesMap} nativeModulesMap [optional] use to customize NativeModules. key is module-name, value is esm url.
15
15
  * @property {NativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
@@ -220,8 +220,8 @@ export class LynxView extends HTMLElement {
220
220
  * @method
221
221
  * update the `__initData` and trigger essential flow
222
222
  */
223
- updateData(data, updateDataType, callback) {
224
- this.#instance?.updateData(data, updateDataType, callback);
223
+ updateData(data, processorName, callback) {
224
+ this.#instance?.updateData(data, processorName, callback);
225
225
  }
226
226
  /**
227
227
  * @public
@@ -1,4 +1,4 @@
1
- import type { Cloneable, SSRDumpInfo, I18nResourceTranslationOptions, InitI18nResources, NapiModulesMap, NativeModulesMap, sendGlobalEventEndpoint, UpdateDataType } from '@lynx-js/web-constants';
1
+ import type { Cloneable, SSRDumpInfo, I18nResourceTranslationOptions, InitI18nResources, NapiModulesMap, NativeModulesMap, sendGlobalEventEndpoint } from '@lynx-js/web-constants';
2
2
  import { type StartUIThreadCallbacks } from '../uiThread/startUIThread.js';
3
3
  import type { RpcCallType } from '@lynx-js/web-worker-rpc';
4
4
  export interface LynxViewConfigs {
@@ -16,7 +16,7 @@ export interface LynxViewConfigs {
16
16
  ssr?: SSRDumpInfo;
17
17
  }
18
18
  export interface LynxView {
19
- updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
19
+ updateData(data: Cloneable, processorName?: string, callback?: () => void): void;
20
20
  dispose(): Promise<void>;
21
21
  sendGlobalEvent: RpcCallType<typeof sendGlobalEventEndpoint>;
22
22
  updateGlobalProps: (data: Cloneable) => void;
@@ -3,6 +3,6 @@ import { Rpc } from '@lynx-js/web-worker-rpc';
3
3
  import type { StartUIThreadCallbacks } from './startUIThread.js';
4
4
  export declare function createRenderAllOnUI(mainToBackgroundRpc: Rpc, shadowRoot: ShadowRoot, loadTemplate: TemplateLoader, markTimingInternal: (timingKey: string, pipelineId?: string, timeStamp?: number) => void, flushMarkTimingInternal: () => void, callbacks: StartUIThreadCallbacks, ssrDumpInfo: SSRDumpInfo | undefined): {
5
5
  start: (configs: StartMainThreadContextConfig) => Promise<void>;
6
- updateDataMainThread: (args_0: Cloneable, args_1: Record<string, string>) => Promise<void>;
6
+ updateDataMainThread: (args_0: Cloneable, args_1: import("@lynx-js/web-constants").UpdateDataOptions | undefined) => Promise<void>;
7
7
  updateI18nResourcesMainThread: (data: Cloneable) => void;
8
8
  };
@@ -1,7 +1,7 @@
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 { i18nResourceMissedEventName, I18nResources, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
4
+ import { updateDataEndpoint, i18nResourceMissedEventName, I18nResources, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
5
5
  import { Rpc } from '@lynx-js/web-worker-rpc';
6
6
  import { dispatchLynxViewEvent } from '../utils/dispatchLynxViewEvent.js';
7
7
  import { createExposureMonitor } from './crossThreadHandlers/createExposureMonitor.js';
@@ -16,27 +16,30 @@ const { prepareMainThreadAPIs, } = await import(
16
16
  * Creates a isolated JavaScript context for executing mts code.
17
17
  * This context has its own global variables and functions.
18
18
  */
19
- function createIFrameRealm(parent) {
19
+ async function createIFrameRealm(parent) {
20
20
  const iframe = document.createElement('iframe');
21
+ const iframeReadyPromise = new Promise((resolve) => {
22
+ const listener = (event) => {
23
+ if (event.data === 'lynx:mtsready' && event.source === iframe.contentWindow) {
24
+ resolve();
25
+ globalThis.removeEventListener('message', listener);
26
+ }
27
+ };
28
+ globalThis.addEventListener('message', listener);
29
+ });
21
30
  iframe.style.display = 'none';
22
31
  iframe.srcdoc =
23
- '<!DOCTYPE html><html><head></head><body style="display:none"></body></html>';
32
+ '<!DOCTYPE html><html><head><script>parent.postMessage("lynx:mtsready","*")</script></head><body style="display:none"></body></html>';
24
33
  iframe.sandbox = 'allow-same-origin allow-scripts'; // Restrict capabilities for security
25
34
  iframe.loading = 'eager';
26
35
  parent.appendChild(iframe);
36
+ await iframeReadyPromise;
27
37
  const iframeWindow = iframe.contentWindow;
28
38
  const loadScript = async (url) => {
29
39
  const script = iframe.contentDocument.createElement('script');
30
40
  script.fetchPriority = 'high';
31
41
  script.defer = true;
32
42
  script.async = false;
33
- if (!iframe.contentDocument.head) {
34
- await new Promise((resolve) => {
35
- iframe.onload = () => resolve();
36
- // In case iframe is already loaded, wait a macro task
37
- setTimeout(() => resolve(), 0);
38
- });
39
- }
40
43
  iframe.contentDocument.head.appendChild(script);
41
44
  return new Promise(async (resolve, reject) => {
42
45
  script.onload = () => {
@@ -82,14 +85,12 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, loadTemplat
82
85
  const i18nResources = new I18nResources();
83
86
  const { exposureChangedCallback } = createExposureMonitor(shadowRoot);
84
87
  const mtsRealm = createIFrameRealm(shadowRoot);
85
- const mtsGlobalThis = mtsRealm.globalWindow;
86
- const { startMainThread } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document, mtsRealm, exposureChangedCallback, markTimingInternal, flushMarkTimingInternal, (err, _, release) => {
88
+ const { startMainThread, handleUpdatedData } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document, mtsRealm, exposureChangedCallback, markTimingInternal, flushMarkTimingInternal, (err, _, release) => {
87
89
  callbacks.onError?.(err, release, 'lepus.js');
88
90
  }, triggerI18nResourceFallback, (initI18nResources) => {
89
91
  i18nResources.setData(initI18nResources);
90
92
  return i18nResources;
91
93
  }, loadTemplate);
92
- const pendingUpdateCalls = [];
93
94
  const start = async (configs) => {
94
95
  if (ssrDumpInfo) {
95
96
  const lynxUniqueIdToElement = [];
@@ -124,20 +125,9 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, loadTemplat
124
125
  else {
125
126
  await startMainThread(configs);
126
127
  }
127
- // Process any pending update calls that were queued while mtsGlobalThis was undefined
128
- for (const args of pendingUpdateCalls) {
129
- mtsGlobalThis.updatePage?.(...args);
130
- }
131
- pendingUpdateCalls.length = 0;
132
128
  };
133
- const updateDataMainThread = async (...args) => {
134
- if (mtsGlobalThis) {
135
- mtsGlobalThis.updatePage?.(...args);
136
- }
137
- else {
138
- // Cache the call if mtsGlobalThis is not yet initialized
139
- pendingUpdateCalls.push(args);
140
- }
129
+ const updateDataMainThread = async (newData, options) => {
130
+ return handleUpdatedData(newData, options);
141
131
  };
142
132
  const updateI18nResourcesMainThread = (data) => {
143
133
  i18nResources.setData(data);
@@ -3,6 +3,6 @@ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
3
  import type { StartUIThreadCallbacks } from './startUIThread.js';
4
4
  export declare function createRenderMultiThread(mainThreadRpc: Rpc, shadowRoot: ShadowRoot, loadTemplate: TemplateLoader, callbacks: StartUIThreadCallbacks): {
5
5
  start: (args_0: import("@lynx-js/web-constants").StartMainThreadContextConfig) => void;
6
- updateDataMainThread: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: Record<string, string>) => Promise<void>;
6
+ updateDataMainThread: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: import("@lynx-js/web-constants").UpdateDataOptions | undefined) => Promise<void>;
7
7
  updateI18nResourcesMainThread: (args_0: import("@lynx-js/web-constants").Cloneable) => void;
8
8
  };
@@ -1,4 +1,4 @@
1
1
  import type { RpcCallType } from '@lynx-js/web-worker-rpc';
2
2
  import type { LynxView } from '../../apis/createLynxView.js';
3
3
  import { updateDataEndpoint } from '@lynx-js/web-constants';
4
- export declare function createUpdateData(updateDataMainThread: RpcCallType<typeof updateDataEndpoint>, updateDataBackground: RpcCallType<typeof updateDataEndpoint>): LynxView['updateData'];
4
+ export declare function createUpdateData(updateDataMainThread: RpcCallType<typeof updateDataEndpoint>): LynxView['updateData'];
@@ -1,14 +1,10 @@
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 createUpdateData(updateDataMainThread, updateDataBackground) {
6
- return (data, _updateDataType, callback) => {
7
- Promise.all([
8
- // There is no need to process options for now, as they have default values.
9
- updateDataMainThread(data, {}),
10
- updateDataBackground(data, {}),
11
- ]).then(() => callback?.());
4
+ import { updateDataEndpoint } from '@lynx-js/web-constants';
5
+ export function createUpdateData(updateDataMainThread) {
6
+ return (data, processorName, callback) => {
7
+ updateDataMainThread(data, { processorName }).then(() => callback?.());
12
8
  };
13
9
  }
14
10
  //# sourceMappingURL=createUpdateData.js.map
@@ -4,6 +4,5 @@ import type { StartUIThreadCallbacks } from './startUIThread.js';
4
4
  export declare function startBackground(backgroundRpc: Rpc, shadowRoot: ShadowRoot, callbacks: StartUIThreadCallbacks): {
5
5
  sendGlobalEvent: (args_0: string, args_1: Cloneable[] | undefined) => void;
6
6
  markTiming: (args_0: import("@lynx-js/web-constants").MarkTiming[]) => void;
7
- updateDataBackground: (args_0: Cloneable, args_1: Record<string, string>) => Promise<void>;
8
7
  updateI18nResourceBackground: (data: InitI18nResources, options: I18nResourceTranslationOptions) => void;
9
8
  };
@@ -1,4 +1,4 @@
1
- import { getCacheI18nResourcesKey, markTimingEndpoint, sendGlobalEventEndpoint, updateDataEndpoint, updateI18nResourceEndpoint, } from '@lynx-js/web-constants';
1
+ import { getCacheI18nResourcesKey, markTimingEndpoint, sendGlobalEventEndpoint, updateI18nResourceEndpoint, } from '@lynx-js/web-constants';
2
2
  import { registerInvokeUIMethodHandler } from './crossThreadHandlers/registerInvokeUIMethodHandler.js';
3
3
  import { registerNativePropsHandler } from './crossThreadHandlers/registerSetNativePropsHandler.js';
4
4
  import { registerNativeModulesCallHandler } from './crossThreadHandlers/registerNativeModulesCallHandler.js';
@@ -22,7 +22,6 @@ export function startBackground(backgroundRpc, shadowRoot, callbacks) {
22
22
  registerReportErrorHandler(backgroundRpc, 'app-service.js', callbacks.onError);
23
23
  const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
24
24
  const markTiming = backgroundRpc.createCall(markTimingEndpoint);
25
- const updateDataBackground = backgroundRpc.createCall(updateDataEndpoint);
26
25
  const updateI18nResourceBackground = (data, options) => {
27
26
  const matchedResources = data.find(i => getCacheI18nResourcesKey(i.options)
28
27
  === getCacheI18nResourcesKey(options));
@@ -33,7 +32,6 @@ export function startBackground(backgroundRpc, shadowRoot, callbacks) {
33
32
  return {
34
33
  sendGlobalEvent,
35
34
  markTiming,
36
- updateDataBackground,
37
35
  updateI18nResourceBackground,
38
36
  };
39
37
  }
@@ -13,7 +13,7 @@ export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, thr
13
13
  const createLynxStartTiming = performance.now() + performance.timeOrigin;
14
14
  const allOnUI = threadStrategy === 'all-on-ui';
15
15
  const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId, allOnUI, configs.browserConfig);
16
- const { markTiming, sendGlobalEvent, updateDataBackground, updateI18nResourceBackground, } = startBackground(backgroundRpc, shadowRoot, callbacks);
16
+ const { markTiming, sendGlobalEvent, updateI18nResourceBackground, } = startBackground(backgroundRpc, shadowRoot, callbacks);
17
17
  const cacheMarkTimings = {
18
18
  records: [],
19
19
  timeout: null,
@@ -43,7 +43,7 @@ export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, thr
43
43
  });
44
44
  });
45
45
  return {
46
- updateData: createUpdateData(updateDataMainThread, updateDataBackground),
46
+ updateData: createUpdateData(updateDataMainThread),
47
47
  dispose: createDispose(backgroundRpc, terminateWorkers),
48
48
  sendGlobalEvent,
49
49
  updateGlobalProps: backgroundRpc.createCall(updateGlobalPropsEndpoint),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.17.2",
3
+ "version": "0.18.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,14 +25,14 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@lynx-js/offscreen-document": "0.1.4",
28
- "@lynx-js/web-constants": "0.17.2",
29
- "@lynx-js/web-mainthread-apis": "0.17.2",
30
- "@lynx-js/web-worker-rpc": "0.17.2",
31
- "@lynx-js/web-worker-runtime": "0.17.2"
28
+ "@lynx-js/web-constants": "0.18.1",
29
+ "@lynx-js/web-mainthread-apis": "0.18.1",
30
+ "@lynx-js/web-worker-rpc": "0.18.1",
31
+ "@lynx-js/web-worker-runtime": "0.18.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@lynx-js/lynx-core": "0.1.3",
35
- "@lynx-js/web-elements": "0.8.7"
35
+ "@lynx-js/web-elements": "0.8.9"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@lynx-js/lynx-core": "0.1.3",