@@ -3,32 +3,70 @@ import { ConvexProvider, ConvexReactClient } from "convex/react";
33import ReactDOM from "react-dom/client" ;
44import Loader from "./components/loader" ;
55import { routeTree } from "./routeTree.gen" ;
6+ import React from "react" ;
67
7- const convex = new ConvexReactClient ( import . meta. env . VITE_CONVEX_URL as string ) ;
8+ const convexUrl = import . meta. env . VITE_CONVEX_URL as string | undefined ;
89
9- const router = createRouter ( {
10- routeTree,
11- defaultPreload : "intent" ,
12- defaultPendingComponent : ( ) => < Loader /> ,
13- context : { } ,
14- Wrap : function WrapComponent ( { children } : { children : React . ReactNode } ) {
15- return < ConvexProvider client = { convex } > { children } </ ConvexProvider > ;
16- } ,
17- } ) ;
18-
19- declare module "@tanstack/react-router" {
20- interface Register {
21- router : typeof router ;
10+ // If the Convex URL isn't set (e.g. missing env var in production), show
11+ // a clear message instead of letting the runtime throw an opaque 404/NOT_FOUND
12+ // from the Convex client. This helps debugging deployed builds (like Vercel)
13+ // when environment variables were not configured.
14+ if ( ! convexUrl || convexUrl . length === 0 ) {
15+ const rootElement = document . getElementById ( "app" ) ;
16+ if ( ! rootElement ) {
17+ throw new Error ( "Root element not found" ) ;
2218 }
23- }
19+ const root = ReactDOM . createRoot ( rootElement ) ;
20+ root . render (
21+ < div className = "min-h-screen flex items-center justify-center p-6 bg-[#f8f3ed]" >
22+ < div className = "max-w-xl w-full bg-white shadow-lg rounded-lg p-6 text-center" >
23+ < h1 className = "text-2xl font-bold mb-2 text-[#7c6a5c]" > Configuração Ausente</ h1 >
24+ < p className = "text-[#7c6a5c] mb-4" >
25+ A aplicação não encontrou a variável de ambiente < code > VITE_CONVEX_URL</ code > .
26+ Defina essa variável no ambiente de execução (por exemplo, nas Environment
27+ Variables do Vercel) com a URL do seu projeto Convex para habilitar o
28+ backend.
29+ </ p >
30+ < div className = "flex justify-center gap-2" >
31+ < a
32+ href = "/"
33+ className = "inline-block px-4 py-2 bg-[#ffa726] text-white rounded font-semibold"
34+ >
35+ Voltar
36+ </ a >
37+ </ div >
38+ </ div >
39+ </ div >
40+ ) ;
41+ // stop further initialization
42+ } else {
43+ const convex = new ConvexReactClient ( convexUrl ) ;
2444
25- const rootElement = document . getElementById ( "app" ) ;
45+ const router = createRouter ( {
46+ routeTree,
47+ defaultPreload : "intent" ,
48+ defaultPendingComponent : ( ) => < Loader /> ,
49+ context : { } ,
50+ Wrap : function WrapComponent ( { children } : { children : React . ReactNode } ) {
51+ return < ConvexProvider client = { convex } > { children } </ ConvexProvider > ;
52+ } ,
53+ } ) ;
2654
27- if ( ! rootElement ) {
28- throw new Error ( "Root element not found" ) ;
29- }
55+ const rootElement = document . getElementById ( "app" ) ;
3056
31- if ( ! rootElement . innerHTML ) {
32- const root = ReactDOM . createRoot ( rootElement ) ;
33- root . render ( < RouterProvider router = { router } /> ) ;
57+ if ( ! rootElement ) {
58+ throw new Error ( "Root element not found" ) ;
59+ }
60+
61+ if ( ! rootElement . innerHTML ) {
62+ const root = ReactDOM . createRoot ( rootElement ) ;
63+ root . render ( < RouterProvider router = { router } /> ) ;
64+ }
3465}
66+
67+ // Keep a minimal ambient declaration so the router type is registered for other files.
68+ declare module "@tanstack/react-router" {
69+ interface Register {
70+ router : any ;
71+ }
72+ }
0 commit comments