Hussein
Hussein
Explore posts from servers
SSolidJS
Created by Hussein on 7/6/2024 in #support
is this a good pattern?
export default function Home() {
const user = createAsync(() => getUser());
const shouldRedirect = createMemo(() => !user());

return <Suspense>{shouldRedirect() && <Navigate href="/login" />}</Suspense>;
}
export default function Home() {
const user = createAsync(() => getUser());
const shouldRedirect = createMemo(() => !user());

return <Suspense>{shouldRedirect() && <Navigate href="/login" />}</Suspense>;
}
32 replies
SSolidJS
Created by Hussein on 7/5/2024 in #support
how do i dedupe requests without `cache`?
i tried everything. it always calls the function either twice or even thrice on client, after the server fetching the data too.
45 replies
SSolidJS
Created by Hussein on 7/3/2024 in #support
is there a way to disable default lazy loading for routes in solidstart?
it seems routes are download when a link to them is clicked and then cached. is there a way to just download all routes on any route like solid spa?
21 replies
SSolidJS
Created by Hussein on 6/30/2024 in #support
how to create brotli files when building?
vinxi build is only creating gz files
6 replies
SSolidJS
Created by Hussein on 6/25/2024 in #support
Error: Cannot find cache context
SSR:
import { cache, createAsync, Route, Router } from "@solidjs/router";
import { Suspense } from "solid-js";

export function App({ url }: { url?: string }) {
return (
<Router url={url}>
<Route
path="/"
component={() => (
<>
Hello World
<a style={{ display: "block", "margin-top": "1em" }} href="/other">
Other
</a>
</>
)}
/>
<Route
path="/other"
component={() => {
const get = cache(async () => {
const res = await fetch(
"https://jsonplaceholder.typicode.com/todos/1"
);
return res.json();
}, "data");

const data = createAsync(() => get());

return (
<>
Other
<Suspense fallback={<p>Loading...</p>}>
<pre>{JSON.stringify(data())}</pre>
</Suspense>
<a style={{ display: "block", "margin-top": "1em" }} href="/">
Home
</a>
</>
);
}}
/>
</Router>
);
}
import { cache, createAsync, Route, Router } from "@solidjs/router";
import { Suspense } from "solid-js";

export function App({ url }: { url?: string }) {
return (
<Router url={url}>
<Route
path="/"
component={() => (
<>
Hello World
<a style={{ display: "block", "margin-top": "1em" }} href="/other">
Other
</a>
</>
)}
/>
<Route
path="/other"
component={() => {
const get = cache(async () => {
const res = await fetch(
"https://jsonplaceholder.typicode.com/todos/1"
);
return res.json();
}, "data");

const data = createAsync(() => get());

return (
<>
Other
<Suspense fallback={<p>Loading...</p>}>
<pre>{JSON.stringify(data())}</pre>
</Suspense>
<a style={{ display: "block", "margin-top": "1em" }} href="/">
Home
</a>
</>
);
}}
/>
</Router>
);
}
92 replies
SSolidJS
Created by Hussein on 5/27/2024 in #support
is hmr broken? or is this intentional?
create new solid start project run dev command change text in index.tsx route it does a full refresh 🤔
8 replies
SSolidJS
Created by Hussein on 5/26/2024 in #support
how to return a 404 error in `cache`?
4 replies
SSolidJS
Created by Hussein on 5/23/2024 in #support
declare types for locals?
i need to declare some locals for RequestEvent
import { User } from "lucia";

declare module "@solidjs/start" {
export interface RequestEventLocals {
user?: User;
}
}
import { User } from "lucia";

declare module "@solidjs/start" {
export interface RequestEventLocals {
user?: User;
}
}
that didn't work
7 replies
SSolidJS
Created by Hussein on 5/21/2024 in #support
how to load data on link hover?
is there a way to preload data on link hover? <Router preload> didn't do anything.
3 replies
SSolidJS
Created by Hussein on 5/21/2024 in #support
how do i redirect on load?
i did this
export const route = {
load: async () => {
"use server";
const cookie = getCookie("chat_session");
if (!cookie) throw redirect("/");
},
};
export const route = {
load: async () => {
"use server";
const cookie = getCookie("chat_session");
if (!cookie) throw redirect("/");
},
};
this is not working
26 replies
SSolidJS
Created by Hussein on 5/21/2024 in #support
how do i use Drizzle?
I'm trying to use Drizzle db on the server only and its giving me "Uncaught TypeError: promisify is not a function" in the browser.
import { cache, createAsync } from "@solidjs/router";
import { db } from "~/lib/db";

const getData = cache(() => {
return db.query.chat.findMany();
}, "data");

export const route = { load: getData };

export default function Home() {
const data = createAsync(() => getData());

return <p>{data()?.length}</p>;
}
import { cache, createAsync } from "@solidjs/router";
import { db } from "~/lib/db";

const getData = cache(() => {
return db.query.chat.findMany();
}, "data");

export const route = { load: getData };

export default function Home() {
const data = createAsync(() => getData());

return <p>{data()?.length}</p>;
}
this is what lib/db looks like
import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import * as schema from "./schema";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";

export const db = drizzle(new Database("db.sqlite"), { schema });
migrate(db, { migrationsFolder: "drizzle" });
import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import * as schema from "./schema";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";

export const db = drizzle(new Database("db.sqlite"), { schema });
migrate(db, { migrationsFolder: "drizzle" });
68 replies
SSolidJS
Created by Hussein on 5/20/2024 in #support
How do i conditionally add something to <head> based on what createAsync returns?
I need to wait for a resource coming from createAsync so then i can decide whether i should add google recaptcha to <head> using useHead from @solidjs/meta
const getChat = cache(async () => {
return { messages: [{ text: "hi", author: "me" }] };
}, "chat");

export default function Contact() {
const chat = createAsync(() => {
return getChat();
});

if (!chat())
useHead({
tag: "script",
id: "recaptcha",
setting: { close: true },
props: {
src: "https://www.google.com/recaptcha/api.js",
async: true,
defer: true,
},
});
const getChat = cache(async () => {
return { messages: [{ text: "hi", author: "me" }] };
}, "chat");

export default function Contact() {
const chat = createAsync(() => {
return getChat();
});

if (!chat())
useHead({
tag: "script",
id: "recaptcha",
setting: { close: true },
props: {
src: "https://www.google.com/recaptcha/api.js",
async: true,
defer: true,
},
});
69 replies
SSolidJS
Created by Hussein on 5/2/2024 in #support
how to use bun:sqlite without it leaking to the browser?
I'm using a Drizzle DB. how do i initialize it and use it in a route file in solid start?
12 replies
SSolidJS
Created by Hussein on 4/20/2024 in #support
Conditionally redirect based on resource result?
i'm fetching the logged in user using this:
const [user] = createResource(async () => {
const me = await trpc.me.query();
return me;
});
const [user] = createResource(async () => {
const me = await trpc.me.query();
return me;
});
how do i redirect based on whether if user is null to /login page using @solidjs/router?
7 replies
DTDrizzle Team
Created by Hussein on 10/27/2023 in #help
example on users table with followers and follows?
I need
3 replies
DTDrizzle Team
Created by Hussein on 10/26/2023 in #help
"Seems like the schema generic is missing - did you forget to add it to your DB type?"
how to fix this... i need to use db.query
19 replies