rtzrtz.
rtzrtz.
Explore posts from servers
SSolidJS
Created by rtzrtz. on 2/10/2025 in #support
SingleFlight does not work (See Example)
In case anyone runs into the same issue, here is a working, minimal example. 🙂
import {
action,
createAsync,
query,
RouteDefinition,
useAction,
} from "@solidjs/router";

const getDate = query(async () => {
"use server";
return new Date().toISOString();
}, "items");

const addAction = action(async () => {
"use server";
// something that might affect the date, who knows
return;
});

export const route = {
preload() {
getDate();
},
} satisfies RouteDefinition;

export default function Flight() {
const date = createAsync(() => getDate(), {
deferStream: true,
});

const someMutation = useAction(addAction);

return (
<div>
<p>{date()}</p>
<button onClick={someMutation}>Add</button>
</div>
);
}
import {
action,
createAsync,
query,
RouteDefinition,
useAction,
} from "@solidjs/router";

const getDate = query(async () => {
"use server";
return new Date().toISOString();
}, "items");

const addAction = action(async () => {
"use server";
// something that might affect the date, who knows
return;
});

export const route = {
preload() {
getDate();
},
} satisfies RouteDefinition;

export default function Flight() {
const date = createAsync(() => getDate(), {
deferStream: true,
});

const someMutation = useAction(addAction);

return (
<div>
<p>{date()}</p>
<button onClick={someMutation}>Add</button>
</div>
);
}
11 replies
SSolidJS
Created by rtzrtz. on 2/10/2025 in #support
SingleFlight does not work (See Example)
it works now, thank you! 🙂
11 replies
SSolidJS
Created by rtzrtz. on 2/10/2025 in #support
SingleFlight does not work (See Example)
thats missing in the docs 😄
11 replies
SSolidJS
Created by rtzrtz. on 2/10/2025 in #support
SingleFlight does not work (See Example)
ohhh, that makes sense
11 replies
SSolidJS
Created by rtzrtz. on 2/10/2025 in #support
SingleFlight does not work (See Example)
though i will mention using const items as shared state isn't entirely reliable, there will be a few copies of it on the server that may not be producing the behaviour you expect
Haha of course, this is just for the minimal prototype here. But either way, items are getting fetched - and I understand SingleFlight would return that fetch with the action-response directly, right?
11 replies
SSolidJS
Created by rtzrtz. on 2/10/2025 in #support
SingleFlight does not work (See Example)
Thank you! I changed it to this, still the same behaviour. 😦
import { action, createAsync, query, reload, useAction } from "@solidjs/router";

const items: string[] = ["yo", "lo", "foo", "bar"];

const getItems = query(async () => {
"use server";
await new Promise((r) => setTimeout(r, 200));
return items;
}, "items");

const addAction = action(async (item: string) => {
"use server";
items.push(item);
return reload();
});

export default function Flight() {
const items = createAsync(() => getItems(),{
deferStream: true,
});

const addItem = useAction(addAction);

return (
<div>
<ul>
{items()?.map((item) => (
<li>{item}</li>
))}
</ul>
<button onClick={() => addItem(Date.now().toString())}>Add</button>
</div>
);
}
import { action, createAsync, query, reload, useAction } from "@solidjs/router";

const items: string[] = ["yo", "lo", "foo", "bar"];

const getItems = query(async () => {
"use server";
await new Promise((r) => setTimeout(r, 200));
return items;
}, "items");

const addAction = action(async (item: string) => {
"use server";
items.push(item);
return reload();
});

export default function Flight() {
const items = createAsync(() => getItems(),{
deferStream: true,
});

const addItem = useAction(addAction);

return (
<div>
<ul>
{items()?.map((item) => (
<li>{item}</li>
))}
</ul>
<button onClick={() => addItem(Date.now().toString())}>Add</button>
</div>
);
}
11 replies
SSolidJS
Created by rtzrtz. on 2/4/2025 in #support
behaviour of createAsync in hooks - why cached?
but every instance of the my hook, (see above, useMyHook) creates a new instance of createAsync as well, and its not triggereing a refetch
14 replies
SSolidJS
Created by rtzrtz. on 2/4/2025 in #support
behaviour of createAsync in hooks - why cached?
i hoped it wouldnt, but im still wondering why it doesnt. When I use const res = createAsync(() => getData()); on PageComponent (Home.tsx) it does refetch on every navigation, right? Why does it not refretch when used inside a hook?
14 replies
SSolidJS
Created by rtzrtz. on 2/4/2025 in #support
behaviour of createAsync in hooks - why cached?
Mh, i just checked, it does not refetch the user, even after 15 seconds or longer
14 replies
SSolidJS
Created by rtzrtz. on 2/4/2025 in #support
behaviour of createAsync in hooks - why cached?
Oh, thats a leftover from my actual code. I just edited it, thanks! Well, I'm using the same instance of the query, but not of the hook, right? I'm using the hook at multiple places, and each hook is a new instance, including the internal createAsync primitive.
14 replies
DTDrizzle Team
Created by rtzrtz. on 11/27/2023 in #help
import of drizzle-orm makes typescript complain about missing "document"
@Nishant Shrestha nope, unfortunately not
5 replies