@lynx-js/web-core-canary 0.15.8-canary-20250827-60c81a1e → 0.16.0-canary-20250828-c1f8715a

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,6 +1,18 @@
1
1
  # @lynx-js/web-core
2
2
 
3
- ## 0.15.8-canary-20250827151323-60c81a1ed99567d7475e661196eb363f992420e6
3
+ ## 0.16.0-canary-20250828064127-c1f8715a81b2e69ff46fc363013626db4468c209
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
 
@@ -10,11 +22,11 @@
10
22
 
11
23
  - fix: the SystemInfo in bts should be assigned to the globalThis ([#1599](https://github.com/lynx-family/lynx-stack/pull/1599))
12
24
 
13
- - Updated dependencies [[`bb53d9a`](https://github.com/lynx-family/lynx-stack/commit/bb53d9a035f607e7c89952098d4ed77877a2e3c1)]:
14
- - @lynx-js/web-mainthread-apis@0.15.8-canary-20250827151323-60c81a1ed99567d7475e661196eb363f992420e6
15
- - @lynx-js/web-worker-runtime@0.15.8-canary-20250827151323-60c81a1ed99567d7475e661196eb363f992420e6
16
- - @lynx-js/web-constants@0.15.8-canary-20250827151323-60c81a1ed99567d7475e661196eb363f992420e6
17
- - @lynx-js/web-worker-rpc@0.15.8-canary-20250827151323-60c81a1ed99567d7475e661196eb363f992420e6
25
+ - Updated dependencies [[`bb53d9a`](https://github.com/lynx-family/lynx-stack/commit/bb53d9a035f607e7c89952098d4ed77877a2e3c1), [`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]:
26
+ - @lynx-js/web-mainthread-apis@0.16.0-canary-20250828064127-c1f8715a81b2e69ff46fc363013626db4468c209
27
+ - @lynx-js/web-worker-runtime@0.16.0-canary-20250828064127-c1f8715a81b2e69ff46fc363013626db4468c209
28
+ - @lynx-js/web-constants@0.16.0-canary-20250828064127-c1f8715a81b2e69ff46fc363013626db4468c209
29
+ - @lynx-js/web-worker-rpc@0.16.0-canary-20250828064127-c1f8715a81b2e69ff46fc363013626db4468c209
18
30
 
19
31
  ## 0.15.7
20
32
 
@@ -12,6 +12,55 @@ const { prepareMainThreadAPIs, } = await import(
12
12
  /* webpackPrefetch: true */
13
13
  /* webpackFetchPriority: "high" */
14
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
+ }
15
64
  export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingInternal, flushMarkTimingInternal, callbacks, ssrDumpInfo) {
16
65
  if (!globalThis.module) {
17
66
  Object.assign(globalThis, { module: {} });
@@ -21,13 +70,14 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
21
70
  };
22
71
  const i18nResources = new I18nResources();
23
72
  const { exposureChangedCallback } = createExposureMonitor(shadowRoot);
24
- const { startMainThread } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document.createElement.bind(document), exposureChangedCallback, markTimingInternal, flushMarkTimingInternal, (err, _, release) => {
73
+ const mtsRealm = createIFrameRealm(shadowRoot);
74
+ const mtsGlobalThis = mtsRealm.globalWindow;
75
+ const { startMainThread } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document, mtsRealm, exposureChangedCallback, markTimingInternal, flushMarkTimingInternal, (err, _, release) => {
25
76
  callbacks.onError?.(err, release, 'lepus.js');
26
77
  }, triggerI18nResourceFallback, (initI18nResources) => {
27
78
  i18nResources.setData(initI18nResources);
28
79
  return i18nResources;
29
80
  });
30
- let mtsGlobalThis;
31
81
  const pendingUpdateCalls = [];
32
82
  const start = async (configs) => {
33
83
  if (ssrDumpInfo) {
@@ -52,7 +102,7 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
52
102
  }
53
103
  }
54
104
  }
55
- mtsGlobalThis = await startMainThread(configs, {
105
+ await startMainThread(configs, {
56
106
  // @ts-expect-error
57
107
  lynxUniqueIdToElement: lynxUniqueIdToElement,
58
108
  lynxUniqueIdToStyleRulesIndex,
@@ -61,7 +111,7 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
61
111
  });
62
112
  }
63
113
  else {
64
- mtsGlobalThis = await startMainThread(configs);
114
+ await startMainThread(configs);
65
115
  }
66
116
  // Process any pending update calls that were queued while mtsGlobalThis was undefined
67
117
  for (const args of pendingUpdateCalls) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core-canary",
3
- "version": "0.15.8-canary-20250827-60c81a1e",
3
+ "version": "0.16.0-canary-20250828-c1f8715a",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,10 +25,10 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@lynx-js/offscreen-document": "npm:@lynx-js/offscreen-document-canary@0.1.3",
28
- "@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.15.8-canary-20250827-60c81a1e",
29
- "@lynx-js/web-mainthread-apis": "npm:@lynx-js/web-mainthread-apis-canary@0.15.8-canary-20250827-60c81a1e",
30
- "@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.15.8-canary-20250827-60c81a1e",
31
- "@lynx-js/web-worker-runtime": "npm:@lynx-js/web-worker-runtime-canary@0.15.8-canary-20250827-60c81a1e"
28
+ "@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.16.0-canary-20250828-c1f8715a",
29
+ "@lynx-js/web-mainthread-apis": "npm:@lynx-js/web-mainthread-apis-canary@0.16.0-canary-20250828-c1f8715a",
30
+ "@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.16.0-canary-20250828-c1f8715a",
31
+ "@lynx-js/web-worker-runtime": "npm:@lynx-js/web-worker-runtime-canary@0.16.0-canary-20250828-c1f8715a"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@lynx-js/lynx-core": "0.1.3",