QwikDev / qwik

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

[🐞] Resource onPending does not render #4328

Open AnthonyPaulO opened 1 year ago

AnthonyPaulO commented 1 year ago

Which component is affected?

Qwik Runtime

Describe the bug

<Resource onPending={...} /> not working; onResolved works just fine, I see the eventual result render on screen, but the "loading" message I want to display in the interim is never rendered.

Screen Shot 2023-05-24 at 11 43 37 AM

Reproduction

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

Steps to reproduce

Go to repro link (created via qwik.new) and do 'npm run dev'

System Info

This is my info, but it also happens in qwik.new online environment.

 System:
    OS: macOS 12.6.2
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 306.66 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 19.1.0 - /usr/local/bin/node
    npm: 9.6.7 - /usr/local/bin/npm
  Browsers:
    Chrome: 113.0.5672.126
    Safari: 15.6.1
  npmPackages:
    @builder.io/qwik: ^1.1.4 => 1.1.4 
    @builder.io/qwik-city: ^1.1.4 => 1.1.4 
    undici: 5.22.1 => 5.22.1 
    vite: 4.3.5 => 4.3.5

Additional Information

No response

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

thejackshelton commented 1 year ago

Referenced Discord channel & a video of the issue

https://i.imgur.com/RYvr7sq.gif

https://discord.com/channels/842438759945601056/1108776276916973578/1108776276916973578

keuller commented 1 year ago

Just to add a comment, during SPA navigation it works perfectly, the only issue I can see is on SSR (refreshing the page). Looks like a streaming issue, not a Resource component issue itself.

gabriiels commented 1 year ago

Hello @manucorporat @zanettin

Same problem, querying an api and always getting unResolved. It doesn't work onPending and onRejected. I have tested the request to the api in server$ and routeLoader$ . Any idea why it doesn't work?

shairez commented 1 year ago

If this happens during SSR only it's a documented limitation because the server is waiting for the promose to be resolved in the server before it streams the rest of the renderred html (currently it can't come back and replace the "loading" to the resolve state)

But there is research that's being done on how to make it work afaik, so we will update as soon as we know

gabriiels commented 1 year ago

Thank you @shairez !

Any alternative solution that you recommend?

eduardvercaemer commented 5 months ago

I think I have a similar issue? I have a Resource on page /foo. When navigating from /bar to /foo on SPA, it just waits until the resource is resolved before rendering anything, which obviously does not work for long-timed resources.

Edit: Wow this is embarrassing, I was missing my onPending callback...