@lynx-js/web-core 0.16.1 → 0.17.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,57 @@
1
1
  # @lynx-js/web-core
2
2
 
3
+ ## 0.17.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @lynx-js/web-constants@0.17.1
9
+ - @lynx-js/web-mainthread-apis@0.17.1
10
+ - @lynx-js/web-worker-rpc@0.17.1
11
+ - @lynx-js/web-worker-runtime@0.17.1
12
+
13
+ ## 0.17.0
14
+
15
+ ### Minor Changes
16
+
17
+ - break(web): temporary remove support for chunk split ([#1739](https://github.com/lynx-family/lynx-stack/pull/1739))
18
+
19
+ Since the global variables cannot be accessed in the splited chunk, we temporary remove supporting for chunk spliting
20
+
21
+ Developers could easily remove the chunk Split settings in Rspeedy for migration
22
+
23
+ ```
24
+ import { defineConfig } from '@lynx-js/rspeedy'
25
+
26
+ export default defineConfig({
27
+ performance: {
28
+ chunkSplit: {
29
+ strategy: 'all-in-one',
30
+ },
31
+ },
32
+ })
33
+ ```
34
+
35
+ ### Patch Changes
36
+
37
+ - fix: lazy component load error ([#1794](https://github.com/lynx-family/lynx-stack/pull/1794))
38
+
39
+ Some special version template may have chunk loading error. We fixed it.
40
+
41
+ - fix: avoid duplicate style transformation ([#1748](https://github.com/lynx-family/lynx-stack/pull/1748))
42
+
43
+ After this commit, we use DAG methods to handle the styleInfos
44
+
45
+ - fix: add sandbox attribute to iframe for enhanced security ([#1709](https://github.com/lynx-family/lynx-stack/pull/1709))
46
+
47
+ - fix: the default template loader won't fetch twice for one url ([#1709](https://github.com/lynx-family/lynx-stack/pull/1709))
48
+
49
+ - Updated dependencies [[`721635d`](https://github.com/lynx-family/lynx-stack/commit/721635de6c1d2d617c7cbaa86e7d816c42d62930), [`93d707b`](https://github.com/lynx-family/lynx-stack/commit/93d707b82a59f7256952e21da6dcad2999f8233d), [`d150ed4`](https://github.com/lynx-family/lynx-stack/commit/d150ed440a4f1e9d9a3a2911adf6e6fa39a0c589)]:
50
+ - @lynx-js/web-mainthread-apis@0.17.0
51
+ - @lynx-js/web-constants@0.17.0
52
+ - @lynx-js/web-worker-runtime@0.17.0
53
+ - @lynx-js/web-worker-rpc@0.17.0
54
+
3
55
  ## 0.16.1
4
56
 
5
57
  ### Patch Changes
@@ -18,24 +18,27 @@ const { prepareMainThreadAPIs, } = await import(
18
18
  */
19
19
  function createIFrameRealm(parent) {
20
20
  const iframe = document.createElement('iframe');
21
- const iframeLoaded = new Promise((resolve) => {
22
- iframe.onload = () => resolve();
23
- });
24
21
  iframe.style.display = 'none';
25
- iframe.src = 'about:blank';
22
+ iframe.srcdoc =
23
+ '<!DOCTYPE html><html><head></head><body style="display:none"></body></html>';
24
+ iframe.sandbox = 'allow-same-origin allow-scripts'; // Restrict capabilities for security
25
+ iframe.loading = 'eager';
26
26
  parent.appendChild(iframe);
27
27
  const iframeWindow = iframe.contentWindow;
28
- const iframeDocument = iframe.contentDocument;
29
- const loadScript = (url) => {
28
+ const loadScript = async (url) => {
29
+ const script = iframe.contentDocument.createElement('script');
30
+ script.fetchPriority = 'high';
31
+ script.defer = true;
32
+ 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
+ iframe.contentDocument.head.appendChild(script);
30
41
  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
42
  script.onload = () => {
40
43
  const ret = iframeWindow?.module?.exports;
41
44
  // @ts-expect-error
@@ -45,7 +48,7 @@ function createIFrameRealm(parent) {
45
48
  script.onerror = (err) => reject(new Error(`Failed to load script: ${url}`, { cause: err }));
46
49
  // @ts-expect-error
47
50
  iframeWindow.module = { exports: undefined };
48
- iframe.contentDocument.head.appendChild(script);
51
+ script.src = url;
49
52
  });
50
53
  };
51
54
  const loadScriptSync = (url) => {
@@ -1,29 +1,40 @@
1
1
  import { generateTemplate, } from '@lynx-js/web-constants';
2
- const templateCache = {};
2
+ const templateCache = new Map();
3
3
  function createJsModuleUrl(content) {
4
4
  return URL.createObjectURL(new Blob([content], { type: 'text/javascript' }));
5
5
  }
6
6
  export function createTemplateLoader(customTemplateLoader, markTimingInternal) {
7
7
  const loadTemplate = async (url) => {
8
8
  markTimingInternal('load_template_start');
9
- const cachedTemplate = templateCache[url];
9
+ const cachedTemplate = templateCache.get(url);
10
10
  if (cachedTemplate) {
11
11
  markTimingInternal('load_template_end');
12
12
  return cachedTemplate;
13
13
  }
14
- const template = customTemplateLoader
15
- ? await customTemplateLoader(url)
16
- : (await (await fetch(url, {
17
- method: 'GET',
18
- })).json());
19
- const decodedTemplate = await generateTemplate(template, createJsModuleUrl);
20
- templateCache[url] = decodedTemplate;
21
- /**
22
- * This will cause a memory leak, which is expected.
23
- * We cannot ensure that the `URL.createObjectURL` created url will never be used, therefore here we keep it for the entire lifetime of this page.
24
- */
25
- markTimingInternal('load_template_end');
26
- return decodedTemplate;
14
+ else {
15
+ const promise = new Promise(async (resolve, reject) => {
16
+ try {
17
+ const template = customTemplateLoader
18
+ ? await customTemplateLoader(url)
19
+ : (await (await fetch(url, {
20
+ method: 'GET',
21
+ })).json());
22
+ const decodedTemplate = await generateTemplate(template, createJsModuleUrl);
23
+ resolve(decodedTemplate);
24
+ }
25
+ catch (e) {
26
+ templateCache.delete(url);
27
+ reject(e);
28
+ }
29
+ });
30
+ templateCache.set(url, promise);
31
+ /**
32
+ * This will cause a memory leak, which is expected.
33
+ * We cannot ensure that the `URL.createObjectURL` created url will never be used, therefore here we keep it for the entire lifetime of this page.
34
+ */
35
+ markTimingInternal('load_template_end');
36
+ return promise;
37
+ }
27
38
  };
28
39
  return loadTemplate;
29
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.16.1",
3
+ "version": "0.17.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.16.1",
29
- "@lynx-js/web-mainthread-apis": "0.16.1",
30
- "@lynx-js/web-worker-rpc": "0.16.1",
31
- "@lynx-js/web-worker-runtime": "0.16.1"
28
+ "@lynx-js/web-constants": "0.17.1",
29
+ "@lynx-js/web-mainthread-apis": "0.17.1",
30
+ "@lynx-js/web-worker-rpc": "0.17.1",
31
+ "@lynx-js/web-worker-runtime": "0.17.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@lynx-js/lynx-core": "0.1.3",
35
- "@lynx-js/web-elements": "0.8.6"
35
+ "@lynx-js/web-elements": "0.8.7"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@lynx-js/lynx-core": "0.1.3",