Tanstack Start useSyncExternalStoreWithSelector Error #5101
-
I am attempting to leverage an app session (like in the examples) to store a captcha text challenge upon loading of a page - using Here's a simple code breakdown: // session.ts
import { useSession } from '@tanstack/react-start/server';
interface Session {
contactCaptchaText: string | null;
}
export function useAppSession() {
if (!process.env.SESSION_PASSWORD) {
throw new Error('SESSION_PASSWORD is not set');
}
return useSession<Session>({
password: process.env.SESSION_PASSWORD,
});
} // lib/server/contact.ts
export const getContactCaptchaFn = async () => {
const session = await useAppSession();
const { captcha, buffer } = await generateCaptcha();
await session.update({
contactCaptchaText: captcha.text,
});
const response = {
captchaChallenge: captcha.text,
captchaImageUrl: `data:image/png;base64,${buffer.toString('base64')}`,
};
return response;
}; // routes/captcha-test.tsx
import { getContactCaptchaFn } from '@/lib/server/contact';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/captcha-test')({
component: RouteComponent,
loader: () => getContactCaptchaFn(),
});
function RouteComponent() {
const { captchaImageUrl } = Route.useLoaderData();
return <img src={captchaImageUrl} alt="Captcha" />;
} The image loads fine, but whenver I use sessions this way I see this error in the Chrome console:
If I update Could someone help me understand what I might be doing wrong here? |
Beta Was this translation helpful? Give feedback.
Answered by
jakeklassen
Sep 9, 2025
Replies: 1 comment
-
So this was unrelated to sessions. I was using a package that required exclusion from SSR flow. My resolved config was: const config = defineConfig(({ command }) => ({
plugins: [
viteTsConfigPaths({
projects: ['./tsconfig.json'],
}),
tailwindcss(),
tanstackStart({
customViteReactPlugin: true,
}),
viteReact(),
],
ssr: {
// Only bundle package-name for production builds
noExternal: command === 'build' ? ['package-name'] : [],
external: command === 'serve' ? ['package-name'] : [],
},
optimizeDeps: {
exclude: ['package-name'],
},
})); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jakeklassen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So this was unrelated to sessions. I was using a package that required exclusion from SSR flow.
My resolved config was: