@lynx-js/web-worker-runtime-canary 0.15.8-canary-20250828-86da1623 → 0.16.0-canary-20250828-09946c26

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,15 +1,27 @@
1
1
  # @lynx-js/web-worker-runtime
2
2
 
3
- ## 0.15.8-canary-20250828061943-86da1623d0bd2cc5fa6dc1642915e5f43a02d350
3
+ ## 0.16.0-canary-20250828065231-09946c2604c0998eba703eea90904d005a0eb1c9
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.
4
16
 
5
17
  ### Patch Changes
6
18
 
7
19
  - fix: the SystemInfo in bts should be assigned to the globalThis ([#1599](https://github.com/lynx-family/lynx-stack/pull/1599))
8
20
 
9
- - Updated dependencies [[`bb53d9a`](https://github.com/lynx-family/lynx-stack/commit/bb53d9a035f607e7c89952098d4ed77877a2e3c1)]:
10
- - @lynx-js/web-mainthread-apis@0.15.8-canary-20250828061943-86da1623d0bd2cc5fa6dc1642915e5f43a02d350
11
- - @lynx-js/web-constants@0.15.8-canary-20250828061943-86da1623d0bd2cc5fa6dc1642915e5f43a02d350
12
- - @lynx-js/web-worker-rpc@0.15.8-canary-20250828061943-86da1623d0bd2cc5fa6dc1642915e5f43a02d350
21
+ - Updated dependencies [[`bb53d9a`](https://github.com/lynx-family/lynx-stack/commit/bb53d9a035f607e7c89952098d4ed77877a2e3c1), [`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]:
22
+ - @lynx-js/web-mainthread-apis@0.16.0-canary-20250828065231-09946c2604c0998eba703eea90904d005a0eb1c9
23
+ - @lynx-js/web-constants@0.16.0-canary-20250828065231-09946c2604c0998eba703eea90904d005a0eb1c9
24
+ - @lynx-js/web-worker-rpc@0.16.0-canary-20250828065231-09946c2604c0998eba703eea90904d005a0eb1c9
13
25
 
14
26
  ## 0.15.7
15
27
 
@@ -1,4 +1,4 @@
1
- import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint, I18nResource, reportErrorEndpoint, globalDisallowedVars, } from '@lynx-js/web-constants';
1
+ import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint, I18nResource, reportErrorEndpoint, } from '@lynx-js/web-constants';
2
2
  import { createInvokeUIMethod } from './crossThreadHandlers/createInvokeUIMethod.js';
3
3
  import { registerPublicComponentEventHandler } from './crossThreadHandlers/registerPublicComponentEventHandler.js';
4
4
  import { registerGlobalExposureEventHandler } from './crossThreadHandlers/registerGlobalExposureEventHandler.js';
@@ -23,30 +23,7 @@ export async function createNativeApp(config) {
23
23
  const reportError = uiThreadRpc.createCall(reportErrorEndpoint);
24
24
  const createBundleInitReturnObj = () => {
25
25
  const entry = globalThis.module.exports;
26
- return {
27
- init: (lynxCoreInject) => {
28
- lynxCoreInject.tt.lynxCoreInject = lynxCoreInject;
29
- lynxCoreInject.tt.globalThis ??= new Proxy(lynxCoreInject, {
30
- get(target, prop) {
31
- if (typeof prop === 'string' && globalDisallowedVars.includes(prop)) {
32
- return undefined;
33
- }
34
- // @ts-expect-error
35
- return target[prop] ?? globalThis[prop];
36
- },
37
- set(target, prop, value) {
38
- // @ts-expect-error
39
- target[prop] = value;
40
- return true;
41
- },
42
- ownKeys(target) {
43
- return Reflect.ownKeys(target).filter((key) => key !== 'globalThis');
44
- },
45
- });
46
- const ret = entry?.(lynxCoreInject.tt);
47
- return ret;
48
- },
49
- };
26
+ return entry;
50
27
  };
51
28
  const i18nResource = new I18nResource();
52
29
  let release = '';
@@ -14,6 +14,26 @@ const { prepareMainThreadAPIs } = await import(
14
14
  /* webpackPrefetch: true */
15
15
  /* webpackFetchPriority: "high" */
16
16
  '@lynx-js/web-mainthread-apis');
17
+ function loadScriptSync(url) {
18
+ importScripts(url);
19
+ return globalThis.module?.exports;
20
+ }
21
+ function loadScript(url) {
22
+ return new Promise((resolve, reject) => {
23
+ fetch(url)
24
+ .then(() => {
25
+ importScripts(url);
26
+ resolve(globalThis.module?.exports);
27
+ }).catch(reject);
28
+ });
29
+ }
30
+ function createCurrentWorkerRealm() {
31
+ return {
32
+ globalWindow: globalThis,
33
+ loadScript,
34
+ loadScriptSync,
35
+ };
36
+ }
17
37
  export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort) {
18
38
  const uiThreadRpc = new Rpc(uiThreadPort, 'main-to-ui');
19
39
  const backgroundThreadRpc = new Rpc(backgroundThreadPort, 'main-to-bg');
@@ -26,14 +46,19 @@ export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort)
26
46
  options,
27
47
  ]);
28
48
  };
29
- const docu = new OffscreenDocument({
49
+ const document = new OffscreenDocument({
30
50
  onCommit: uiFlush,
31
51
  });
52
+ Object.assign(globalThis, {
53
+ document,
54
+ });
55
+ const mtsRealm = createCurrentWorkerRealm();
32
56
  const i18nResources = new I18nResources();
33
- uiThreadRpc.registerHandler(postOffscreenEventEndpoint, docu[_onEvent]);
57
+ uiThreadRpc.registerHandler(postOffscreenEventEndpoint, document[_onEvent]);
34
58
  const sendMultiThreadExposureChangedEndpoint = uiThreadRpc.createCall(multiThreadExposureChangedEndpoint);
35
- const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, docu, docu.createElement.bind(docu), (exposureChangedElementUniqueIds) => {
36
- docu.commit();
59
+ const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, document, // rootDom
60
+ document, mtsRealm, (exposureChangedElementUniqueIds) => {
61
+ document.commit();
37
62
  sendMultiThreadExposureChangedEndpoint(exposureChangedElementUniqueIds
38
63
  .map(e => e.getAttribute(lynxUniqueIdAttribute))
39
64
  .filter(id => id !== null));
@@ -41,10 +66,9 @@ export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort)
41
66
  i18nResources.setData(initI18nResources);
42
67
  return i18nResources;
43
68
  });
44
- uiThreadRpc.registerHandler(mainThreadStartEndpoint, (config) => {
45
- startMainThread(config).then((runtime) => {
46
- registerUpdateDataHandler(uiThreadRpc, runtime);
47
- });
69
+ uiThreadRpc.registerHandler(mainThreadStartEndpoint, async (config) => {
70
+ await startMainThread(config);
71
+ registerUpdateDataHandler(uiThreadRpc, globalThis);
48
72
  });
49
73
  uiThreadRpc?.registerHandler(updateI18nResourcesEndpoint, data => {
50
74
  i18nResources.setData(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-worker-runtime-canary",
3
- "version": "0.15.8-canary-20250828-86da1623",
3
+ "version": "0.16.0-canary-20250828-09946c26",
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": "npm:@lynx-js/offscreen-document-canary@0.1.3",
26
- "@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.15.8-canary-20250828-86da1623",
27
- "@lynx-js/web-mainthread-apis": "npm:@lynx-js/web-mainthread-apis-canary@0.15.8-canary-20250828-86da1623",
28
- "@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.15.8-canary-20250828-86da1623"
26
+ "@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.16.0-canary-20250828-09946c26",
27
+ "@lynx-js/web-mainthread-apis": "npm:@lynx-js/web-mainthread-apis-canary@0.16.0-canary-20250828-09946c26",
28
+ "@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.16.0-canary-20250828-09946c26"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@lynx-js/lynx-core": "0.1.3"