@lynx-js/web-core 0.15.6 → 0.16.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 +43 -0
- package/dist/uiThread/bootWorkers.d.ts +2 -1
- package/dist/uiThread/bootWorkers.js +12 -7
- package/dist/uiThread/createRenderAllOnUI.js +61 -5
- package/dist/uiThread/crossThreadHandlers/createExposureMonitor.js +1 -1
- package/dist/uiThread/startUIThread.js +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @lynx-js/web-core
|
|
2
2
|
|
|
3
|
+
## 0.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- refactor: provide the mts a real globalThis ([#1589](https://github.com/lynx-family/lynx-stack/pull/1589))
|
|
8
|
+
|
|
9
|
+
Before this change, We create a function wrapper and a fake globalThis for Javascript code.
|
|
10
|
+
|
|
11
|
+
This caused some issues.
|
|
12
|
+
|
|
13
|
+
After this change, we will create an iframe for createing an isolated Javascript context.
|
|
14
|
+
|
|
15
|
+
This means the globalThis will be the real one.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- refactor: add `:not([l-e-name])` at the end of selector for lazy component ([#1622](https://github.com/lynx-family/lynx-stack/pull/1622))
|
|
20
|
+
|
|
21
|
+
- feat: remove multi-thread mts heating ([#1597](https://github.com/lynx-family/lynx-stack/pull/1597))
|
|
22
|
+
|
|
23
|
+
The default rendering mode is "all-on-ui". Therefore the preheating for "multi-thread" will be removed.
|
|
24
|
+
|
|
25
|
+
- fix: the SystemInfo in bts should be assigned to the globalThis ([#1599](https://github.com/lynx-family/lynx-stack/pull/1599))
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`1a32dd8`](https://github.com/lynx-family/lynx-stack/commit/1a32dd886fe736c95639f67028cf7685377d9769), [`bb53d9a`](https://github.com/lynx-family/lynx-stack/commit/bb53d9a035f607e7c89952098d4ed77877a2e3c1), [`1a32dd8`](https://github.com/lynx-family/lynx-stack/commit/1a32dd886fe736c95639f67028cf7685377d9769), [`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]:
|
|
28
|
+
- @lynx-js/web-mainthread-apis@0.16.0
|
|
29
|
+
- @lynx-js/web-constants@0.16.0
|
|
30
|
+
- @lynx-js/web-worker-runtime@0.16.0
|
|
31
|
+
- @lynx-js/offscreen-document@0.1.4
|
|
32
|
+
- @lynx-js/web-worker-rpc@0.16.0
|
|
33
|
+
|
|
34
|
+
## 0.15.7
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- fix: fake uidisappear event ([#1539](https://github.com/lynx-family/lynx-stack/pull/1539))
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [[`70863fb`](https://github.com/lynx-family/lynx-stack/commit/70863fbc311d8885ebda40855668097b0631f521)]:
|
|
41
|
+
- @lynx-js/web-mainthread-apis@0.15.7
|
|
42
|
+
- @lynx-js/web-constants@0.15.7
|
|
43
|
+
- @lynx-js/web-worker-runtime@0.15.7
|
|
44
|
+
- @lynx-js/web-worker-rpc@0.15.7
|
|
45
|
+
|
|
3
46
|
## 0.15.6
|
|
4
47
|
|
|
5
48
|
### Patch Changes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { type BrowserConfig } from '@lynx-js/web-constants';
|
|
1
2
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
3
|
interface LynxViewRpc {
|
|
3
4
|
mainThreadRpc: Rpc;
|
|
4
5
|
backgroundRpc: Rpc;
|
|
5
6
|
terminateWorkers: () => void;
|
|
6
7
|
}
|
|
7
|
-
export declare function bootWorkers(lynxGroupId: number | undefined, allOnUI
|
|
8
|
+
export declare function bootWorkers(lynxGroupId: number | undefined, allOnUI: boolean, browserConfig: BrowserConfig): LynxViewRpc;
|
|
8
9
|
export {};
|
|
@@ -1,20 +1,19 @@
|
|
|
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 { systemInfo } from '@lynx-js/web-constants';
|
|
4
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
5
6
|
const backgroundWorkerContextCount = [];
|
|
6
7
|
const contextIdToBackgroundWorker = [];
|
|
7
|
-
|
|
8
|
-
export function bootWorkers(lynxGroupId, allOnUI) {
|
|
8
|
+
export function bootWorkers(lynxGroupId, allOnUI, browserConfig) {
|
|
9
9
|
let curMainWorker;
|
|
10
10
|
if (allOnUI) {
|
|
11
11
|
curMainWorker = createUIChannel();
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
curMainWorker =
|
|
15
|
-
preHeatedMainWorker = createMainWorker();
|
|
14
|
+
curMainWorker = createMainWorker();
|
|
16
15
|
}
|
|
17
|
-
const curBackgroundWorker = createBackgroundWorker(lynxGroupId, curMainWorker.channelMainThreadWithBackground);
|
|
16
|
+
const curBackgroundWorker = createBackgroundWorker(lynxGroupId, curMainWorker.channelMainThreadWithBackground, browserConfig);
|
|
18
17
|
if (lynxGroupId !== undefined) {
|
|
19
18
|
if (backgroundWorkerContextCount[lynxGroupId]) {
|
|
20
19
|
backgroundWorkerContextCount[lynxGroupId]++;
|
|
@@ -71,7 +70,7 @@ function createMainWorker() {
|
|
|
71
70
|
channelMainThreadWithBackground,
|
|
72
71
|
};
|
|
73
72
|
}
|
|
74
|
-
function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground) {
|
|
73
|
+
function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground, browserConfig) {
|
|
75
74
|
const channelToBackground = new MessageChannel();
|
|
76
75
|
let backgroundThreadWorker;
|
|
77
76
|
if (lynxGroupId) {
|
|
@@ -86,6 +85,7 @@ function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground) {
|
|
|
86
85
|
mode: 'background',
|
|
87
86
|
toUIThread: channelToBackground.port2,
|
|
88
87
|
toPeerThread: channelMainThreadWithBackground.port2,
|
|
88
|
+
systemInfo: { ...systemInfo, ...browserConfig },
|
|
89
89
|
};
|
|
90
90
|
backgroundThreadWorker.postMessage(backgroundThreadMessage, [
|
|
91
91
|
channelToBackground.port2,
|
|
@@ -95,7 +95,12 @@ function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground) {
|
|
|
95
95
|
return { backgroundRpc, backgroundThreadWorker };
|
|
96
96
|
}
|
|
97
97
|
function createWebWorker(name) {
|
|
98
|
-
return new Worker(
|
|
98
|
+
return new Worker(
|
|
99
|
+
/* webpackFetchPriority: "high" */
|
|
100
|
+
/* webpackChunkName: "web-core-worker-runtime" */
|
|
101
|
+
/* webpackPrefetch: true */
|
|
102
|
+
/* webpackPreload: true */
|
|
103
|
+
new URL('@lynx-js/web-worker-runtime', import.meta.url), {
|
|
99
104
|
type: 'module',
|
|
100
105
|
name,
|
|
101
106
|
});
|
|
@@ -5,7 +5,62 @@ import { i18nResourceMissedEventName, I18nResources, lynxUniqueIdAttribute, } fr
|
|
|
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';
|
|
8
|
-
const { prepareMainThreadAPIs, } = await import(
|
|
8
|
+
const { prepareMainThreadAPIs, } = await import(
|
|
9
|
+
/* webpackChunkName: "web-core-main-thread-apis" */
|
|
10
|
+
/* webpackMode: "lazy-once" */
|
|
11
|
+
/* webpackPreload: true */
|
|
12
|
+
/* webpackPrefetch: true */
|
|
13
|
+
/* webpackFetchPriority: "high" */
|
|
14
|
+
'@lynx-js/web-mainthread-apis');
|
|
15
|
+
/**
|
|
16
|
+
* Creates a isolated JavaScript context for executing mts code.
|
|
17
|
+
* This context has its own global variables and functions.
|
|
18
|
+
*/
|
|
19
|
+
function createIFrameRealm(parent) {
|
|
20
|
+
const iframe = document.createElement('iframe');
|
|
21
|
+
const iframeLoaded = new Promise((resolve) => {
|
|
22
|
+
iframe.onload = () => resolve();
|
|
23
|
+
});
|
|
24
|
+
iframe.style.display = 'none';
|
|
25
|
+
iframe.src = 'about:blank';
|
|
26
|
+
parent.appendChild(iframe);
|
|
27
|
+
const iframeWindow = iframe.contentWindow;
|
|
28
|
+
const iframeDocument = iframe.contentDocument;
|
|
29
|
+
const loadScript = (url) => {
|
|
30
|
+
return new Promise(async (resolve, reject) => {
|
|
31
|
+
if (iframeDocument.readyState !== 'complete') {
|
|
32
|
+
await iframeLoaded;
|
|
33
|
+
}
|
|
34
|
+
const script = iframeDocument.createElement('script');
|
|
35
|
+
script.src = url;
|
|
36
|
+
script.fetchPriority = 'high';
|
|
37
|
+
script.defer = true;
|
|
38
|
+
script.async = false;
|
|
39
|
+
script.onload = () => resolve(iframeWindow?.module?.exports);
|
|
40
|
+
script.onerror = (err) => reject(new Error(`Failed to load script: ${url}`, { cause: err }));
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
iframeWindow.module = { exports: undefined };
|
|
43
|
+
iframe.contentDocument.head.appendChild(script);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const loadScriptSync = (url) => {
|
|
47
|
+
const xhr = new XMLHttpRequest();
|
|
48
|
+
xhr.open('GET', url, false); // Synchronous request
|
|
49
|
+
xhr.send(null);
|
|
50
|
+
if (xhr.status === 200) {
|
|
51
|
+
const script = iframe.contentDocument.createElement('script');
|
|
52
|
+
script.textContent = xhr.responseText;
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
iframeWindow.module = { exports: undefined };
|
|
55
|
+
iframe.contentDocument.head.appendChild(script);
|
|
56
|
+
return iframeWindow?.module?.exports;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error(`Failed to load script: ${url}`, { cause: xhr });
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return { globalWindow: iframeWindow, loadScript, loadScriptSync };
|
|
63
|
+
}
|
|
9
64
|
export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingInternal, flushMarkTimingInternal, callbacks, ssrDumpInfo) {
|
|
10
65
|
if (!globalThis.module) {
|
|
11
66
|
Object.assign(globalThis, { module: {} });
|
|
@@ -15,13 +70,14 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
|
|
|
15
70
|
};
|
|
16
71
|
const i18nResources = new I18nResources();
|
|
17
72
|
const { exposureChangedCallback } = createExposureMonitor(shadowRoot);
|
|
18
|
-
const
|
|
73
|
+
const mtsRealm = createIFrameRealm(shadowRoot);
|
|
74
|
+
const mtsGlobalThis = mtsRealm.globalWindow;
|
|
75
|
+
const { startMainThread } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document, mtsRealm, exposureChangedCallback, markTimingInternal, flushMarkTimingInternal, (err, _, release) => {
|
|
19
76
|
callbacks.onError?.(err, release, 'lepus.js');
|
|
20
77
|
}, triggerI18nResourceFallback, (initI18nResources) => {
|
|
21
78
|
i18nResources.setData(initI18nResources);
|
|
22
79
|
return i18nResources;
|
|
23
80
|
});
|
|
24
|
-
let mtsGlobalThis;
|
|
25
81
|
const pendingUpdateCalls = [];
|
|
26
82
|
const start = async (configs) => {
|
|
27
83
|
if (ssrDumpInfo) {
|
|
@@ -46,7 +102,7 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
|
|
|
46
102
|
}
|
|
47
103
|
}
|
|
48
104
|
}
|
|
49
|
-
|
|
105
|
+
await startMainThread(configs, {
|
|
50
106
|
// @ts-expect-error
|
|
51
107
|
lynxUniqueIdToElement: lynxUniqueIdToElement,
|
|
52
108
|
lynxUniqueIdToStyleRulesIndex,
|
|
@@ -55,7 +111,7 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
|
|
|
55
111
|
});
|
|
56
112
|
}
|
|
57
113
|
else {
|
|
58
|
-
|
|
114
|
+
await startMainThread(configs);
|
|
59
115
|
}
|
|
60
116
|
// Process any pending update calls that were queued while mtsGlobalThis was undefined
|
|
61
117
|
for (const args of pendingUpdateCalls) {
|
|
@@ -38,7 +38,7 @@ export function createExposureMonitor(rootDom) {
|
|
|
38
38
|
sendExposureEvent(target, true, target.getAttribute('exposure-id'));
|
|
39
39
|
exposedElements.add(target);
|
|
40
40
|
}
|
|
41
|
-
else {
|
|
41
|
+
else if (!isIntersecting && exposedElements.has(target)) {
|
|
42
42
|
sendExposureEvent(target, false, target.getAttribute('exposure-id'));
|
|
43
43
|
exposedElements.delete(target);
|
|
44
44
|
}
|
|
@@ -12,7 +12,7 @@ import { createRenderAllOnUI } from './createRenderAllOnUI.js';
|
|
|
12
12
|
export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, threadStrategy, callbacks, ssr) {
|
|
13
13
|
const createLynxStartTiming = performance.now() + performance.timeOrigin;
|
|
14
14
|
const allOnUI = threadStrategy === 'all-on-ui';
|
|
15
|
-
const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId, allOnUI);
|
|
15
|
+
const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId, allOnUI, configs.browserConfig);
|
|
16
16
|
const { markTiming, sendGlobalEvent, updateDataBackground, updateI18nResourceBackground, } = startBackground(backgroundRpc, shadowRoot, callbacks);
|
|
17
17
|
const cacheMarkTimings = {
|
|
18
18
|
records: [],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"**/*.css"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lynx-js/offscreen-document": "0.1.
|
|
28
|
-
"@lynx-js/web-constants": "0.
|
|
29
|
-
"@lynx-js/web-mainthread-apis": "0.
|
|
30
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
31
|
-
"@lynx-js/web-worker-runtime": "0.
|
|
27
|
+
"@lynx-js/offscreen-document": "0.1.4",
|
|
28
|
+
"@lynx-js/web-constants": "0.16.0",
|
|
29
|
+
"@lynx-js/web-mainthread-apis": "0.16.0",
|
|
30
|
+
"@lynx-js/web-worker-rpc": "0.16.0",
|
|
31
|
+
"@lynx-js/web-worker-runtime": "0.16.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@lynx-js/lynx-core": "0.1.3",
|