From b18c3ca71cce4f22b21eaae76cc73d58e5310fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=90?= <31800073+Parsifa1@users.noreply.github.com> Date: Sat, 14 Dec 2024 14:41:28 +0800 Subject: [PATCH] fix: compatibility for some old chromium core (#995) * fix: compatibility for some old chromium core * feat: resolve relative URL manually * dev: revert the change * dev: add some comment * fix: wrong regrex in 50228956 * dev: upgrade version to use --------- Co-authored-by: Myriad-Dreamin --- Cargo.lock | 21 ++++++++++++++------- Cargo.toml | 2 +- tools/typst-dom/package.json | 8 ++++---- tools/typst-dom/src/typst-doc.mts | 3 ++- tools/typst-preview-frontend/package.json | 4 ++-- tools/typst-preview-frontend/src/main.js | 12 +++++++++--- yarn.lock | 18 +++++++++--------- 7 files changed, 41 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9fbfb7d94..2bb9aa612 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,6 +49,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -1386,6 +1392,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash 0.8.11", + "allocator-api2", ] [[package]] @@ -1396,9 +1403,9 @@ checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "hashlink" -version = "0.9.1" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ "hashbrown 0.14.5", ] @@ -4021,7 +4028,7 @@ dependencies = [ "serde_yaml", "strum", "sync-lsp", - "tinymist-assets 0.12.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tinymist-assets 0.12.11-rc1", "tinymist-query", "tinymist-render", "tinymist-world", @@ -4069,9 +4076,9 @@ version = "0.12.10" [[package]] name = "tinymist-assets" -version = "0.12.10" +version = "0.12.11-rc1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0d4ca0df1e38258ae8e1e0841173a903e7d6707c22632cb75c8661b0f1c4ed7" +checksum = "4681522ebaea59bc7b880377f2c4c28f928d842b1980475a476780614e2d6fd5" [[package]] name = "tinymist-derive" @@ -4164,7 +4171,7 @@ dependencies = [ "serde", "serde_json", "tar", - "tinymist-assets 0.12.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tinymist-assets 0.12.11-rc1", "typst", "typst-assets", ] @@ -4607,7 +4614,7 @@ dependencies = [ "reflexo-vec2svg", "serde", "serde_json", - "tinymist-assets 0.12.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tinymist-assets 0.12.11-rc1", "tokio", "typst", "typst-assets", diff --git a/Cargo.toml b/Cargo.toml index cc5edacca..9d942bbfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -145,7 +145,7 @@ insta = { version = "1.39", features = ["glob"] } # Our Own Crates typst-preview = { path = "./crates/typst-preview" } -tinymist-assets = { version = "0.12.10" } +tinymist-assets = { version = "0.12.11-rc1" } tinymist = { path = "./crates/tinymist/" } tinymist-derive = { path = "./crates/tinymist-derive/" } tinymist-analysis = { path = "./crates/tinymist-analysis/" } diff --git a/tools/typst-dom/package.json b/tools/typst-dom/package.json index 45c544f41..7077789e0 100644 --- a/tools/typst-dom/package.json +++ b/tools/typst-dom/package.json @@ -13,12 +13,12 @@ "unlink:local": "yarn unlink @myriaddreamin/typst.ts @myriaddreamin/typst-ts-renderer" }, "peerDependencies": { - "@myriaddreamin/typst-ts-renderer": "0.5.0-rc9", - "@myriaddreamin/typst.ts": "0.5.0-rc9" + "@myriaddreamin/typst-ts-renderer": "0.5.1", + "@myriaddreamin/typst.ts": "0.5.1" }, "devDependencies": { - "@myriaddreamin/typst-ts-renderer": "0.5.0-rc9", - "@myriaddreamin/typst.ts": "0.5.0-rc9", + "@myriaddreamin/typst-ts-renderer": "0.5.1", + "@myriaddreamin/typst.ts": "0.5.1", "typescript": "^5.0.2" }, "exports": { diff --git a/tools/typst-dom/src/typst-doc.mts b/tools/typst-dom/src/typst-doc.mts index a857a0624..549741029 100644 --- a/tools/typst-dom/src/typst-doc.mts +++ b/tools/typst-dom/src/typst-doc.mts @@ -165,7 +165,8 @@ export class TypstDocumentContext { static derive(ctx: any, mode: string) { return ["rescale", "rerender", "postRender"].reduce( (acc: any, x: string) => { - acc[x] = ctx[`${x}$${mode}`].bind(ctx); + let index = x + "$" + mode; + acc[x] = ctx[index].bind(ctx); console.assert(acc[x] !== undefined, `${x}$${mode} is undefined`); return acc; }, diff --git a/tools/typst-preview-frontend/package.json b/tools/typst-preview-frontend/package.json index 675ceba39..5c4fd1b8b 100644 --- a/tools/typst-preview-frontend/package.json +++ b/tools/typst-preview-frontend/package.json @@ -13,8 +13,8 @@ "unlink:local": "yarn unlink @myriaddreamin/typst.ts @myriaddreamin/typst-ts-renderer" }, "dependencies": { - "@myriaddreamin/typst-ts-renderer": "0.5.0-rc9", - "@myriaddreamin/typst.ts": "0.5.0-rc9", + "@myriaddreamin/typst-ts-renderer": "0.5.1", + "@myriaddreamin/typst.ts": "0.5.1", "typst-dom": "link:../typst-dom", "rxjs": "^7.8.1" } diff --git a/tools/typst-preview-frontend/src/main.js b/tools/typst-preview-frontend/src/main.js index 7ee52aaa2..a5d4dc005 100644 --- a/tools/typst-preview-frontend/src/main.js +++ b/tools/typst-preview-frontend/src/main.js @@ -37,13 +37,19 @@ function retrieveWsArgs() { /// The string `ws://127.0.0.1:23625` is a placeholder /// Also, it is the default url to connect to. - let url = "ws://127.0.0.1:23625"; + /// Note that we must resolve the url to an absolute url as + /// the websocket connection requires an absolute url. + /// + /// See [WebSocket and relative URLs](https://github.com/whatwg/websockets/issues/20) + let urlObject = new URL("ws://127.0.0.1:23625", window.location.href); + /// Rewrite the protocol to websocket. + urlObject.protocol = urlObject.protocol.replace('https:', 'wss:').replace('http:', 'ws:'); if (location.href.startsWith("https://")) { - url = url.replace("ws://", "wss://") + urlObject.protocol = urlObject.protocol.replace('ws:', 'wss:'); } /// Return a `WsArgs` object. - return { url, previewMode, isContentPreview: false }; + return { url: urlObject.href, previewMode, isContentPreview: false }; } /// `buildWs` returns a object, which keeps track of websocket diff --git a/yarn.lock b/yarn.lock index c4751c157..0c4a16b25 100644 --- a/yarn.lock +++ b/yarn.lock @@ -408,15 +408,15 @@ resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz#3188bcb273a414b0d215fd22a58540b989b9409a" integrity sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ== -"@myriaddreamin/typst-ts-renderer@0.5.0-rc9": - version "0.5.0-rc9" - resolved "https://registry.yarnpkg.com/@myriaddreamin/typst-ts-renderer/-/typst-ts-renderer-0.5.0-rc9.tgz#c6ed3ce01c7ce61a83b396bdd39c412b56dedcd8" - integrity sha512-YyKvGcTmCpzzv+M54vQA8zaDfMM/PqsQrThDi9DG1D5FOKt50w8+xE5POEFPfDu5y9iVyvJ/AhkRqGyy4njkcQ== - -"@myriaddreamin/typst.ts@0.5.0-rc9": - version "0.5.0-rc9" - resolved "https://registry.yarnpkg.com/@myriaddreamin/typst.ts/-/typst.ts-0.5.0-rc9.tgz#0d9c4c61406b0245105544d821dae5a0a88a39fc" - integrity sha512-6mnxNzuEp4ALFwzuvvCTijM756G1VUnXie9TwjCb01ey3f6jv/Xh1rWNwLds2KUYAtDdaOqO7RMctOhvqdq0rg== +"@myriaddreamin/typst-ts-renderer@0.5.1": + version "0.5.1" + resolved "https://registry.yarnpkg.com/@myriaddreamin/typst-ts-renderer/-/typst-ts-renderer-0.5.1.tgz#951bb1df75c93c29b1072b71fe375fb030a8bde2" + integrity sha512-3kTixY1a9mAlfJuWCBv28DUYEhmjXdPSV8970I0/bhwOH9wqekGb2WB5BkDc+ZfEDUUx4nI51VOPmdSJZwDJ7w== + +"@myriaddreamin/typst.ts@0.5.1": + version "0.5.1" + resolved "https://registry.yarnpkg.com/@myriaddreamin/typst.ts/-/typst.ts-0.5.1.tgz#903deb5fff1b66c7381763611712fcdc72919da1" + integrity sha512-1G58PfWNzZp9TOgsn1v+uqL5wYvppAFcwhqBAj1/Gszelp+/t+4UeyIiF6V1S3tegQMkvtd6bPo06X+dSGTqgg== dependencies: idb "^7.1.1"