Skip to content

[🐞] [v1 & v2] SPA routing is broken unless origin matches value in in vite.config #8093

@termermc

Description

@termermc

Which component is affected?

Qwik City

Describe the bug

On the static and Cloudflare adapters (and most likely all others with SSG capabilities), SPA <Link> routing results in a full page reload unless origin is set the adapter's vite.config.ts, and the actual origin matches it.

This issue affects both v1 and v2.

Assuming your SSG settings have an origin of http://localhost:3000:

If you visit http://localhost:3000 (origin match) from your browser, <Link> SPA routing and useNavigate will work properly.

If you visit http://127.0.0.1:3000 (origin mismatch) from your browser, Clicking a <Link> will result in a full page reload, as if it was a plain <a>. Calls to useNavigate will work, but using the browser history back and forward buttons will result in full page reloads.

This is a problem because this makes using preview environments (like on workers.dev) or local testing of prod builds impossible. It also makes it impossible to serve the same application from multiple domains, like serving on both a domain and the www subdomain of that domain. Using <Link> and useNavigate with relative paths should not depend on a specific origin.

Thank you!

Reproduction

https://github.com/termermc/qwik-spa-bug-repro

Steps to reproduce

  1. Create a new Qwik City app
  2. Add add the static adapter
  3. Edit the origin in the adapter's vite.config.ts to http://localhost:3000
  4. Add some <Link> components to navigate between different pages
  5. Build the project with pnpm run build
  6. Start a webserver listening on 0.0.0.0:3000 at the root of dist
  7. Visit http://localhost:3000, notice clicking links uses SPA routing
  8. Visit http://127.0.0.1:3000, notice clicking links causes full page reloads

System Info

System:
    OS: Linux 6.17 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
    Memory: 89.55 GB / 125.72 GB
    Container: Yes
    Shell: 4.1.2 - /usr/bin/fish
  Binaries:
    Node: 24.9.0 - /usr/sbin/node
    Yarn: 1.22.22 - /usr/sbin/yarn
    npm: 11.6.2 - /usr/sbin/npm
    pnpm: 10.18.3 - /usr/sbin/pnpm
    bun: 1.3.1 - /home/termer/.bun/bin/bun
    Deno: 2.5.1 - /home/termer/.deno/bin/deno
  Browsers:
    Firefox: 144.0
    Firefox Developer Edition: 144.0

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions