@lynx-js/web-core 0.18.0 → 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,21 @@
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
+
3
19
  ## 0.18.0
4
20
 
5
21
  ### Minor Changes
@@ -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
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 [newData, options] of pendingUpdateCalls) {
129
- handleUpdatedData(newData, options);
130
- }
131
- pendingUpdateCalls.length = 0;
132
128
  };
133
129
  const updateDataMainThread = async (newData, options) => {
134
- if (mtsGlobalThis) {
135
- return handleUpdatedData(newData, options);
136
- }
137
- else {
138
- // Cache the call if mtsGlobalThis is not yet initialized
139
- pendingUpdateCalls.push([newData, options]);
140
- }
130
+ return handleUpdatedData(newData, options);
141
131
  };
142
132
  const updateI18nResourcesMainThread = (data) => {
143
133
  i18nResources.setData(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.18.0",
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.18.0",
29
- "@lynx-js/web-mainthread-apis": "0.18.0",
30
- "@lynx-js/web-worker-rpc": "0.18.0",
31
- "@lynx-js/web-worker-runtime": "0.18.0"
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.8"
35
+ "@lynx-js/web-elements": "0.8.9"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@lynx-js/lynx-core": "0.1.3",