QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.77k stars 1.3k forks source link

[🐞] useLocation does not re-trigger useTask$() in static adapter output #5820

Closed mrclay closed 3 months ago

mrclay commented 8 months ago

Which component is affected?

Qwik City (routing)

Describe the bug

When trying to track location changes, the useTask$ hook fails to re-fire the hook body if the project is built with the static adapter.

Example component code:

  const loc = useLocation();
  useTask$(({ track }) => {
    track(() => loc.url);
    console.log(1);
  });

In dev mode, this works, but after npm run build the code in dist does not re-call the useTask$ given function.

Reproduction

https://stackblitz.com/edit/qwik-starter-oaexpi?file=src%2Froutes%2Findex.tsx

Steps to reproduce

npm ci
npm run build.client
npm run build.server
npx serve dist

View http://localhost:3000. When clicking the links, the state should update with the useLocation() value.

System Info

  System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 77.03 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.1 - ~/.nvm/versions/node/v21.6.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v21.6.1/bin/npm
    pnpm: 8.5.0 - ~/Library/pnpm/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
  Browsers:
    Chrome: 121.0.6167.139
    Safari: 17.2.1
  npmPackages:
    @builder.io/qwik: ^1.4.3 => 1.4.3 
    @builder.io/qwik-city: ^1.4.3 => 1.4.3 
    undici: ^6.6.0 => 6.6.0 
    vite: ^5.0.12 => 5.0.12

Additional Information

No response

mrclay commented 8 months ago

As far as I can tell my general roadblock is static Qwik sites don't use SPA navigation, even if you use navigate(), and that I'm trying to rebuild what was originally a React SPA with react-router-dom. I figured "I'll get Qwik to make a fast loading default for my base route then mutate when SPA nav happens." I may need to roll my own custom useRouter for this use case.

wmertens commented 8 months ago

This definitely looks like a bug. I presume this does work with the node adapter?

mrclay commented 8 months ago

I've not tested the node adapter specifically. It works with npm run dev. I can test the node adapter later.

wmertens commented 8 months ago

Please do, thank you!

gioboa commented 4 months ago

@mrclay Did you solve the problem?

github-actions[bot] commented 4 months ago

Hello @mrclay. Please provide the missing information requested above. Issues marked with STATUS-2: missing info will be automatically closed if they have no activity within 14 days. Thanks 🙏