qwik icon indicating copy to clipboard operation
qwik copied to clipboard

[🐞] Use <Resource... /> with routeLoader$

Open gabriiels opened this issue 1 year ago • 1 comments

Which component is affected?

Qwik City (routing)

Describe the bug

Using a graphql library (@urql/core) with routeLoader

The problem is the following:

When you query a graphql api and want to read the results in a <Resource ...>, you only get onResolved . But onPending and onRejected don't work

gabriiels avatar Apr 26 '23 02:04 gabriiels

it's hard we will find time to look into this issue without a repo case, ie, something we can play with, fix and finally integrate as a regression test.

Also, missing some of the parts of the template, such as which version is it etc.

manucorporat avatar May 10 '23 00:05 manucorporat

As far as I understand, routerLoader$ by design does not returns a Promise but it returns a Signal. If you want to use <Resource .../> to load data my suggestion it to use a combination useResource$ + server$. The snippet below does it.

export const getData = server$(() => {
    return new Promise((resolve) => {
        setTimeout(() => resolve(1), 1000) 
    });
});

export default component$(() => {
    const data = useResource$(() => getData());
    return (
        <>
            <Resource value={data} 
                onPending={() => <>Loading..</>}
                onResolved={(val) => <>{val}</>}
            />
        </>
    )
});

The side effect of this approach is a weird (looks like a bug to me), when you navigates to the page via SPA the streaming behavior works perfectly, but once you're in the page and reload the page rendering is synchronous which means your user will wait until the Promise resolves to continue the rendering process.

Related issue 4178

keuller avatar May 18 '23 15:05 keuller

Thank you for submitting this issue @gabriiels !

Without a link to a reproduction repo or a playground environment that showcases the issue, we cannot simulate it and work on it's fix.

So we're closing this issue for now, to keep things organized, but feel free to re-open this issue when you'll have the time to create a project / stackblitz / playground that showcases the issue.

Thanks!

shairez avatar Aug 13 '23 09:08 shairez