Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Javascript Logical OR operator throws SyntaxError #10829

Closed
lnfel opened this issue Aug 30, 2024 · 8 comments
Closed

[bug] Javascript Logical OR operator throws SyntaxError #10829

lnfel opened this issue Aug 30, 2024 · 8 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@lnfel
Copy link

lnfel commented Aug 30, 2024

Describe the bug

Trying out Tauri 2.x RC with sveltekit 2.x and it seems failing to recognize Logical OR ||= operator in JavaScript.

This is the exact line of code in sveltekit repo that throws an error when running pnpm tauri dev:
https://github.com/sveltejs/kit/blob/45cb8c5f305b4d9e61a32e19af8059dc0da4c255/packages/kit/src/runtime/client/client.js#L305

According to the author, it is valid JavaScript:
sveltejs/kit#12040

As seen on MDN docs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment

I have another tauri project that uses sveltekit 1.x, they have pending_invalidate = pending_invalidate || Promise.resolve(); in it but in 2.x they changed it to await (pending_invalidate ||= Promise.resolve());.

Not sure whether the issue is with tauri, wry or tao, it would be nice if someone can help.

Reproduction

https://github.com/lnfel/tauri2.xrc-svelte5

Expected behavior

Expected the JavaScript logical OR operator ||= to be a valid syntax.

Full tauri info output

[✔] Environment
    - OS: Mac OS 10.15.7 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.80.1 (3f5fd8dd4 2024-08-06)
    ✔ cargo: 1.80.1 (376290515 2024-07-16)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-apple-darwin (default)
    - node: 22.6.0
    - pnpm: 8.6.3
    - npm: 10.8.2
    - bun: 1.0.14

[-] Packages
    - tauri [RUST]: 2.0.0-rc.6
    - tauri-build [RUST]: 2.0.0-rc.6
    - wry [RUST]: 0.42.0
    - tao [RUST]: 0.29.1
    - @tauri-apps/api [NPM]: 2.0.0-rc.3
    - @tauri-apps/cli [NPM]: 2.0.0-rc.7

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../build
    - devUrl: http://localhost:5173/
    - framework: Svelte
    - bundler: Vite

Stack trace

Stack trace is seen on tauri app window by opening devtools (alt + cmd + i on macOS):

Unhandled Promise Rejection: SyntaxError: Unexpected token '='
    (anonymous function) - client.js:305
    promiseReactionJob


### Additional context

_No response_
@lnfel lnfel added status: needs triage This issue needs to triage, applied to new issues type: bug labels Aug 30, 2024
@Legend-Master
Copy link
Contributor

I'm not the most familiar with mac but from your system information, Mac OS 10.15.7 comes with webkit 608 which corresponding to safari 13, and ||= is added in safari 14

@lnfel
Copy link
Author

lnfel commented Aug 30, 2024

I'm not the most familiar with mac but from your system information, Mac OS 10.15.7 comes with webkit 608 which corresponding to safari 13, and ||= is added in safari 14

I don't quite understand yet, does this mean Tauri/Wry uses the webkit version that comes with my macOS version. Resulting to the issue since ||= is not available yet. My other projects that uses sveltekit 2.x are working fine when running on chrome browser, I guess they have their own bundle of webkit? The only issue I have is when running sveltekit 2.x with tauri.

Is there a possible work-around on this issue or I am stuck? I've been hoping to build cross platform apps using tauri...

Maybe I can run a script that changes a specific code on sveltekit package before running tauri dev/build? I have no longer any capabilities to update my device so getting updates on Safari is out of the picture.

@Legend-Master
Copy link
Contributor

Tauri uses the webview (in this case webkit on macos) provided by the OS, for your case, you can try changing build.target to something like es2020 in vite config

@lnfel
Copy link
Author

lnfel commented Aug 30, 2024

I got the build release working after adding es2020 as build target but pnpm tauri dev still points to the sveltekit pnpm package that has the ||= operator.

@Legend-Master
Copy link
Contributor

Try esbuild: { target: 'es2020' } in vite config?

@lnfel
Copy link
Author

lnfel commented Aug 30, 2024

Try esbuild: { target: 'es2020' } in vite config?

Tried it, no transformation happens during dev start, the target option might only be available during build. I overwritten the code directly and it now works. This is obviously not the correct way to do it but the build release is working fine so I will go with this for now.

@Legend-Master
Copy link
Contributor

Some people suggested using optimizeDeps.esbuildOptions.target instead, maybe give it a shot?

vitejs/vite#13756

@Legend-Master
Copy link
Contributor

I'm closing this for now since it's not really a problem that tauri can fix, feel free to keep the conversation going though

@Legend-Master Legend-Master closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

2 participants