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>
);
}
43 Replies
Hussein
Hussein2w ago
this only happens when going to /other from a new tab. when going to /other from the link in / it works fine. it means the browser router is working, but the server router isn't
bigmistqke 🌈
move
const get = cache(async () => {
const res = await fetch(
"https://jsonplaceholder.typicode.com/todos/1"
);
return res.json();
}, "data");
const get = cache(async () => {
const res = await fetch(
"https://jsonplaceholder.typicode.com/todos/1"
);
return res.json();
}, "data");
out of the component?
Hussein
Hussein7d ago
will did not work
bigmistqke 🌈
how does your code look now?
Hussein
Hussein7d ago
moved it to App and outside of App too both didn't work
import { cache, createAsync, Route, Router } from "@solidjs/router";
import { Suspense } from "solid-js";

const get = cache(async () => {
const res = await fetch("https://jsonplaceholder.typicode.com/todos/1");
return res.json();
}, "data");

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 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";

const get = cache(async () => {
const res = await fetch("https://jsonplaceholder.typicode.com/todos/1");
return res.json();
}, "data");

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 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>
);
}
and
import { cache, createAsync, Route, Router } from "@solidjs/router";
import { Suspense } from "solid-js";

export function App({ url }: { url?: string }) {
const get = cache(async () => {
const res = await fetch("https://jsonplaceholder.typicode.com/todos/1");
return res.json();
}, "data");

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 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 }) {
const get = cache(async () => {
const res = await fetch("https://jsonplaceholder.typicode.com/todos/1");
return res.json();
}, "data");

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 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>
);
}
same error
bigmistqke 🌈
this one I expected to work.
Hussein
Hussein7d ago
the error is purely ssr btw it never happens on the client and only on the /other page i tried wrapping App with Suspense didn't work either
bigmistqke 🌈
I just ran your code from a fresh pnpm create solid@latest and with this sample and I do not get an error. I had to change export App to export default App
Hussein
Hussein7d ago
are u doing ssr?
bigmistqke 🌈
think so lemme check
Hussein
Hussein7d ago
{
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.13.6",
"solid-js": "^1.8.17",
"vite-plugin-solid": "^2.10.2",
"vite": "^5.3.1"
}
{
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.13.6",
"solid-js": "^1.8.17",
"vite-plugin-solid": "^2.10.2",
"vite": "^5.3.1"
}
bigmistqke 🌈
i think it defaults to ssr right
Hussein
Hussein7d ago
do our versions match?
bigmistqke 🌈
"dependencies": {
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.13.6",
"@solidjs/start": "^1.0.2",
"solid-js": "^1.8.17",
"vinxi": "^0.3.12"
}
"dependencies": {
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.13.6",
"@solidjs/start": "^1.0.2",
"solid-js": "^1.8.17",
"vinxi": "^0.3.12"
}
Hussein
Hussein7d ago
but does pnpm create solid offer vanilla solid ssr? i think it only offers csr solid or solidstart i'm using vanilla solid ssr
bigmistqke 🌈
wait ooo i see ur not using solid-start
Hussein
Hussein7d ago
yep otherwise my App would look different
bigmistqke 🌈
kind of important to add that information how so?
Hussein
Hussein7d ago
App would use FileRoutes or something like that in solidstart
bigmistqke 🌈
no FileRoutes is optional as i said, i literally copied your code and it works you can have config based routing
Hussein
Hussein7d ago
interesting
bigmistqke 🌈
or even mix and match i would recommend using solid-start if you want ssr it has its own set of bugs since it is still early 1.0, but it is where all the focus/support on ssr is these days.
Hussein
Hussein7d ago
isn't solidstart v1 already?
bigmistqke 🌈
yes exactly early 1.0
Hussein
Hussein7d ago
ah
bigmistqke 🌈
the api will not have drastic changes
Hussein
Hussein7d ago
understandable. its still a bug worth reporting tho. i will create a repo
bigmistqke 🌈
true, or at least if vanilla ssr does not support the @solidjs/router it should be communicated clearly.
Hussein
Hussein7d ago
it does https://github.com/huseeiin/solidjs-bug-repro you need to have bun installed, sadly
bigmistqke 🌈
Ok, so ur using bun too. It would be good to mention this information from the start If SSR deviates from solid-start, if ur using bun/deno or another runtime that is not node.
Hussein
Hussein7d ago
hm i don't think so but idk just tried in node, it doesn't work either all i changed is Bun.file to readFileSync to work with node :D https://github.com/solidjs/solid-router/blob/main/src/data/cache.ts#L34 this is where the error happens its because i'm not using provideRequestEvent i think yeah probably that
bigmistqke 🌈
I can reproduce the error on my end, but tbh it's a bit too far from what I have knowledge in to help u with But ye, the error has probably something to do with that custom SSR setup I know bun when using solid-start actually uses node under the hood because it is missing some APIs
Hussein
Hussein7d ago
custom ssr is hard but not impossible bun has some problem with FormData in solidstart but everything else works fine with --bun (if you run bun --bun dev bun uses bun runtime, not node)
bigmistqke 🌈
GitHub
GitHub - DaniGuardiola/bun-plugin-solid: A plugin to compile Solid....
A plugin to compile Solid.js with Bun. Contribute to DaniGuardiola/bun-plugin-solid development by creating an account on GitHub.
Hussein
Hussein7d ago
oh this is for bundling i think i use vite
bigmistqke 🌈
I might give it a shot one day 😁
Hussein
Hussein7d ago
i don't care about bun bundler bun doesn't support solidjs style of jsx that's the only blocker only react/preact works
bigmistqke 🌈
Ye no transforms right, only to h-calls
Hussein
Hussein7d ago
but if you use bun with vite, solid is just gonna be processed with esbuild and rollup, so bun doesn't care anymore :D
bigmistqke 🌈
Lol all this stuff is very much out of my comfort zone. Gets so confusing haha Abstractions on top of abstractions. Turtles all the way down!
Hussein
Hussein7d ago
i fixed it
bigmistqke 🌈
Nice! What was it in the end?
Hussein
Hussein7d ago
. provideRequestEvent