tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
78.54k stars 2.33k forks source link

[bug] V2 Next.js config assetPrefix breaks hot reload feature #9804

Closed mattma closed 1 week ago

mattma commented 2 weeks ago

Describe the bug

Following the Next.js integration Doc, step 3 contains the configuration below. Next.js hot reload feature won't work properly.

  // Configure assetPrefix or else the server won't properly resolve your assets.
  assetPrefix: isProd ? null : `http://${internalHost}:3000`,

I can even reproduce the issue by running Next.js app only in the browser, or running in desktop app by tauri dev. The terminal process will report the compiled status when the file changes have been made, but no hot reload in the browser or in the native desktop simulator.

By comment out the line assetPrefix, hot reload works as expected but it will break the feature the server won't properly resolve your assets..

Reproduction

  1. Follow the create tauri app guide
  2. Remove the Vite app, and replaced with fresh generated Next.js app by following guide

Expected behavior

  // Configure assetPrefix or else the server won't properly resolve your assets.
  assetPrefix: isProd ? null : `http://${internalHost}:3000`,

The next.js integration guide, with assetPrefix in place, next.js hot reload on code change should work.

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.4.1 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
    ✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.1.0
    - pnpm: 9.1.0
    - yarn: 1.22.22
    - npm: 10.7.0

[-] Packages
    - tauri [RUST]: 2.0.0-beta.19
    - tauri-build [RUST]: 2.0.0-beta.15
    - wry [RUST]: 0.39.5
    - tao [RUST]: 0.28.0
    - @tauri-apps/api [NPM]: 2.0.0-beta.11
    - @tauri-apps/cli [NPM]: 2.0.0-beta.17

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../out
    - devUrl: http://localhost:3000/
    - framework: React (Next.js)
    - bundler: Webpack

Stack trace

No response

Additional context

No response

FabianLars commented 2 weeks ago

Hmm, I feel like it'd be better to reach out to the nextjs community instead. As far as we know we simply need this config and I don't think it's our fault if hmr breaks because of it 🤔

We'd appreciate it if you (or anyone reading this) could take on this :)

mattma commented 1 week ago

I confirmed that the issue is indeed on Next.js side. Tauri side works as expected.