@@ -50,6 +50,7 @@ import {
50
50
publicEnvVariablesType ,
51
51
} from "cyberstorm/security/publicEnvVariables" ;
52
52
import { StorageManager } from "@thunderstore/ts-api-react/src/storage" ;
53
+ import { Route } from "./+types/root" ;
53
54
54
55
// REMIX TODO: https://remix.run/docs/en/main/route/links
55
56
// export const links: LinksFunction = () => [{ rel: "stylesheet", href: styles }];
@@ -119,7 +120,7 @@ export async function loader() {
119
120
} ;
120
121
}
121
122
122
- export async function clientLoader ( ) {
123
+ export async function clientLoader ( { request } : Route . ClientLoaderArgs ) {
123
124
const publicEnvVariables = getPublicEnvVariables ( [
124
125
"VITE_SITE_URL" ,
125
126
"VITE_BETA_SITE_URL" ,
@@ -142,13 +143,28 @@ export async function clientLoader() {
142
143
publicEnvVariables . VITE_COOKIE_DOMAIN
143
144
) ;
144
145
145
- // We need to run this here too in addition to the, shouldRevalidate function,
146
- // as for some reason the commtis to localStorage are not done before the the clientLoader is run
147
- sessionTools . sessionValid (
148
- publicEnvVariables . VITE_API_URL ,
149
- publicEnvVariables . VITE_COOKIE_DOMAIN
146
+ let forceUpdateCurrentUser = false ;
147
+ if (
148
+ request . url . startsWith ( `${ publicEnvVariables . VITE_BETA_SITE_URL } /teams` ) ||
149
+ request . url . startsWith ( `${ publicEnvVariables . VITE_BETA_SITE_URL } /settings` )
150
+ ) {
151
+ forceUpdateCurrentUser = true ;
152
+ } else {
153
+ // In all other cases check if actually need to fetch
154
+ // current-user data. Ideally we shouldn't need to do
155
+ // this sessionValid check again, but for some reason
156
+ // we need to run this here too in addition to the,
157
+ // shouldRevalidate function, cause for some reason
158
+ // the commits to localStorage are not done before
159
+ // the clientLoader is run.
160
+ sessionTools . sessionValid (
161
+ publicEnvVariables . VITE_API_URL ,
162
+ publicEnvVariables . VITE_COOKIE_DOMAIN
163
+ ) ;
164
+ }
165
+ const currentUser = await sessionTools . getSessionCurrentUser (
166
+ forceUpdateCurrentUser
150
167
) ;
151
- const currentUser = await sessionTools . getSessionCurrentUser ( ) ;
152
168
const config = sessionTools . getConfig ( publicEnvVariables . VITE_API_URL ) ;
153
169
return {
154
170
publicEnvVariables : publicEnvVariables ,
@@ -164,11 +180,17 @@ export type RootLoadersType = typeof loader | typeof clientLoader;
164
180
// this needs to be fixed, but it requires a more in-depth solution
165
181
export function shouldRevalidate ( {
166
182
defaultShouldRevalidate,
183
+ nextUrl,
167
184
} : ShouldRevalidateFunctionArgs ) {
168
185
const publicEnvVariables = getPublicEnvVariables ( [
169
186
"VITE_API_URL" ,
170
187
"VITE_COOKIE_DOMAIN" ,
171
188
] ) ;
189
+ if (
190
+ nextUrl . pathname . startsWith ( "/teams" ) ||
191
+ nextUrl . pathname . startsWith ( "/settings" )
192
+ )
193
+ return true ;
172
194
sessionValid (
173
195
new StorageManager ( SESSION_STORAGE_KEY ) ,
174
196
publicEnvVariables . VITE_API_URL || "" ,
0 commit comments