Troubleshooting and gotchas
Problems a new developer meets on the Naalya site, each one listed by what you see, with the cause and the fix.
Find what you see in the headings below, or in the quick reference table at the end. Each entry gives the symptom (what you see), the cause, and the fix. Most of these problems are deliberate choices, wiring that is not finished, or old template files, so nothing looks wrong when they happen.
Nothing on the site validates your setup: there is no .env schema, no pinned Node version, and no type check on GROQ results. So a problem often shows as a blank section or a missing value, not an error. Check the environment, Node, and the global CLI before you debug the code.
Setup problems
These three happen on the first day, before you change any code. The full setup is in Getting Started.
command not found: chowbea-axios
Symptom. Every pnpm api:* script stops with command not found after a clean pnpm install.
Cause. The typed REST client is generated by a CLI called chowbea-axios that is installed globally. It is not in package.json, so pnpm install does not put it in node_modules/.bin. The one exception is api:generate:fetch, which runs a committed Node script and works offline.
Fix. Install the CLI once, globally:
pnpm add -g chowbea-axiosThe scripts then run. You do not need the CLI to start the site, because the generated files under app/services/api/_generated/ are committed. You need it only to regenerate them. The API Client covers the full workflow.
Fetches fail, or the chat widget is missing
Symptom. Fetches fail, or the chat widget never appears.
Cause. .env.example is committed and .env is gitignored, so a fresh clone has no .env. createClient accepts undefined, so a missing Sanity variable often fails later as an empty response. The chat widget returns null when VITE_API_URL or VITE_NAALYA_API_KEY is unset.
Fix. Copy .env.example to .env and fill in development values. The form write token is SANITY_WRITE_TOKEN, with no VITE_ prefix, because POST /api/form-submission reads it on the server. Do not put that token in a VITE_ variable.
Every page is blank on the first run
Symptom. The site starts, but every page is blank.
Cause. The frontend points at the production dataset. The Studio sets projectId: "hdefozzv" and dataset: "development" in sanity/sanity.config.ts, and the frontend must use the same values from the environment. The production dataset is empty or holds other content.
Fix. Set the dataset in .env to development, to match the Studio.
Problems that look like bugs
The first is a missing setting. The second is the code working as designed.
A form submission is not saved to Sanity
Symptom. The enquiry or contact form succeeds, but no submission appears in the Studio, and the server logs SANITY_WRITE_TOKEN is not set; cannot store form submission.
Cause. The browser does not write to Sanity. The form posts to the site's own POST /api/form-submission route, which writes with the server-only client (app/lib/sanity-write-client.server.ts) and SANITY_WRITE_TOKEN. That variable is read at runtime, not built into the bundle like the VITE_* variables.
Fix. Set SANITY_WRITE_TOKEN in the server's environment and restart the server. Do not add a VITE_ prefix, because that puts the token in the browser bundle.
A VITE_ variable changes only with a rebuild
VITE_* values are built into the bundle, so you cannot change them on a running server. On Railway, pass VITE_SANITY_* as Docker build arguments (ARG). A change to any of them needs a rebuild, not a restart. Setup has the Dockerfile ARG block.
Every detail page returns 404 after a refactor
Symptom. After a change to a route loader, every blog post returns 404, including posts that exist.
Cause. The loader returns a real 404 by prefetching the document and then reading it back from the cache synchronously. That works only when the prefetch is awaited first. Without the await, or with the lines in the other order, getQueryData reads an empty cache and the guard runs on every request.
await queryClient.prefetchQuery(BlogPostOptions.blogPost(params.postSlug));
const post = queryClient.getQueryData(["blog-post", params.postSlug]);
if (!post) throw new Response("Post not found", { status: 404 });Fix. Await the prefetch, then read the cache, in that order. The full pattern is in Single Documents & Singletons.
Wiring that is not finished
The code for these three looks complete. It is installed but not connected.
Toasts ignore the theme
Symptom. You turn on dark mode, but toast notifications (Sonner) stay in the wrong theme. Today _layout.tsx forces the light theme, so you see this only after that changes.
Cause. Two hooks have the same name. The app's theme system is a custom Zustand store in app/components/providers/theme.provider.tsx, which exports a hook named useTheme. But app/components/ui/sonner.tsx imports useTheme from the next-themes package. next-themes is in package.json, but its provider is never mounted, so its useTheme always returns the "system" default.
import { useTheme } from "next-themes"; // wrong source: provider never mounted
const { theme = "system" } = useTheme();Fix. In the Toaster, import useTheme from @/components/providers/theme.provider. That is the live hook, and it saves the theme to localStorage as naalya-theme. Whenever you see useTheme, check the import path. next-themes is left over from the shadcn scaffold. Styling & Theming describes the Zustand theme system.
Site settings are fetched twice
Symptom. Server logs or Sanity usage show the siteSettings singleton fetched twice for each page render.
Cause. Two server loaders read it separately. app/root.tsx fetches it with the Sanity client, outside TanStack Query, for the favicon and document shell. app/routes/_layout.tsx then prefetches it through SiteSettingsOptions so the navbar and footer render with CMS data. The browser does not fetch it a third time: useSiteSettings reads the cache that the layout dehydrated.
const siteSettings = await sanityClient.fetch<SiteSettingsDTO>(SITE_SETTINGS_QUERY);Fix. Usually no fix is needed, because it is one small extra request. To remove it, make the root loader read from the same query cache instead of calling the client. See Querying with GROQ.
The pre-commit hook does not check anything
Symptom. A commit with unformatted code passes the pre-commit hook.
Cause. pnpm install runs the prepare script (husky) and sets up git hooks, but the only hook does nothing. .husky/pre-commit prints two lines and exits with success. It runs no formatter, linter, or tests.
echo "Running pre-commit checks..."
echo "Pre-commit checks passed."
exit 0Fix. Run Biome yourself before you push. For a real check, replace the hook body with a command such as pnpm biome check. Until then, the "Pre-commit checks passed." message means nothing.
Files that are out of date
Two committed files say things that are not true for this project.
The README is the stock "Welcome to React Router!" template. It says to run npm install and npm run dev, and it does not mention pnpm, the global CLI, the Sanity Studio, or code generation. Use package.json and this handbook as the source of truth, and use pnpm, not npm, yarn, or bun.
The singleton doc, sanity/SINGLETON_PATTERN.md, explains why singletons exist but lists only a few examples. The full list is the exclusion array in sanity/sanity.config.ts, with about 75 types. To check whether a type is a singleton, read the config. Single Documents & Singletons covers how the config enforces it.
A GROQ field missing from its DTO is undefined at runtime
Sanity TypeGen is not set up for the frontend, so a GROQ result comes back as any and the hook casts it with as to a hand-written DTO. If you add a field to a projection but not to the DTO, TypeScript reports nothing and the field is undefined at runtime. Change the projection and the DTO together. See Project Structure.
Quick reference
Each row is one entry above, by what you see.
| Symptom | Cause | Fix |
|---|---|---|
command not found: chowbea-axios | The CLI is global and not in package.json | Run pnpm add -g chowbea-axios |
| Fetches fail after a clone | No .env was made from .env.example | Copy the example and fill in development values |
| Every page is blank on the first run | The frontend points at production, not development | Use the dataset that the Studio sets |
Older docs show the write token as a VITE_ variable | The form route reads SANITY_WRITE_TOKEN on the server | Keep the token out of the client bundle |
| Every detail page returns 404 | getQueryData ran before the awaited prefetch | Await the prefetch, then read |
| Toasts ignore the theme | Sonner reads next-themes, which is never mounted | Import useTheme from the Zustand provider |
siteSettings is fetched twice | The root loader fetches it, and the layout loader prefetches it | No fix needed; to remove it, share one query cache |
| Unformatted code passes the hook | .husky/pre-commit does nothing | Run Biome yourself, and replace the hook body |
Where to go next
Getting Started
The setup steps in order: pnpm, the global CLI, and your .env file.
Setup
The read-only Sanity client and the server-side form write.
Querying with GROQ
The read path, the direct fetch in the root loader, and why DTOs drift.
Single Documents & Singletons
The 404 pattern in the loader and where the full singleton list lives.