-
Notifications
You must be signed in to change notification settings - Fork 5
Ensure current user is updated #1540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -141,6 +141,13 @@ export async function clientLoader() { | |||||||||||||||||||||||||||||||||||||||||||
publicEnvVariables.VITE_API_URL, | ||||||||||||||||||||||||||||||||||||||||||||
publicEnvVariables.VITE_COOKIE_DOMAIN | ||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// We need to run this here too in addition to the, shouldRevalidate function, | ||||||||||||||||||||||||||||||||||||||||||||
// as for some reason the commits to localStorage are not done before the the clientLoader is run | ||||||||||||||||||||||||||||||||||||||||||||
sessionTools.sessionValid( | ||||||||||||||||||||||||||||||||||||||||||||
publicEnvVariables.VITE_API_URL, | ||||||||||||||||||||||||||||||||||||||||||||
publicEnvVariables.VITE_COOKIE_DOMAIN | ||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||
const currentUser = await sessionTools.getSessionCurrentUser(); | ||||||||||||||||||||||||||||||||||||||||||||
const config = sessionTools.getConfig(publicEnvVariables.VITE_API_URL); | ||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||
|
@@ -158,25 +165,22 @@ export type RootLoadersType = typeof loader | typeof clientLoader; | |||||||||||||||||||||||||||||||||||||||||||
export function shouldRevalidate({ | ||||||||||||||||||||||||||||||||||||||||||||
defaultShouldRevalidate, | ||||||||||||||||||||||||||||||||||||||||||||
}: ShouldRevalidateFunctionArgs) { | ||||||||||||||||||||||||||||||||||||||||||||
if (defaultShouldRevalidate) return true; | ||||||||||||||||||||||||||||||||||||||||||||
const publicEnvVariables = getPublicEnvVariables([ | ||||||||||||||||||||||||||||||||||||||||||||
"VITE_API_URL", | ||||||||||||||||||||||||||||||||||||||||||||
"VITE_COOKIE_DOMAIN", | ||||||||||||||||||||||||||||||||||||||||||||
]); | ||||||||||||||||||||||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||||||||||||||||||||||
!sessionValid( | ||||||||||||||||||||||||||||||||||||||||||||
new StorageManager(SESSION_STORAGE_KEY), | ||||||||||||||||||||||||||||||||||||||||||||
publicEnvVariables.VITE_API_URL || "", | ||||||||||||||||||||||||||||||||||||||||||||
publicEnvVariables.VITE_COOKIE_DOMAIN || "" | ||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||||||||||||||||||
return getSessionStale(new NamespacedStorageManager(SESSION_STORAGE_KEY)); | ||||||||||||||||||||||||||||||||||||||||||||
sessionValid( | ||||||||||||||||||||||||||||||||||||||||||||
new StorageManager(SESSION_STORAGE_KEY), | ||||||||||||||||||||||||||||||||||||||||||||
publicEnvVariables.VITE_API_URL || "", | ||||||||||||||||||||||||||||||||||||||||||||
publicEnvVariables.VITE_COOKIE_DOMAIN || "" | ||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||
const sessionIsStale = getSessionStale( | ||||||||||||||||||||||||||||||||||||||||||||
new NamespacedStorageManager(SESSION_STORAGE_KEY) | ||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||
return sessionIsStale || defaultShouldRevalidate; | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+172
to
+180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical logic bug: The sessionValid() function call is no longer being used to determine revalidation behavior. In the original code, if sessionValid() returned false, the function would return true to trigger revalidation. Now sessionValid() is called but its return value is ignored, and revalidation only depends on sessionIsStale and defaultShouldRevalidate. This means invalid sessions will no longer trigger revalidation, potentially leaving users with stale data when their session becomes invalid. The fix should capture the sessionValid() return value and include it in the revalidation logic:
Suggested change
Spotted by Diamond |
||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+172
to
181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against empty envs to avoid clobbering storage; reuse a single storage instance. Passing "" into Apply this diff within this block: - sessionValid(
- new StorageManager(SESSION_STORAGE_KEY),
- publicEnvVariables.VITE_API_URL || "",
- publicEnvVariables.VITE_COOKIE_DOMAIN || ""
- );
- const sessionIsStale = getSessionStale(
- new NamespacedStorageManager(SESSION_STORAGE_KEY)
- );
- return sessionIsStale || defaultShouldRevalidate;
+ const apiHost = publicEnvVariables.VITE_API_URL;
+ const cookieDomain = publicEnvVariables.VITE_COOKIE_DOMAIN;
+ if (!apiHost || !cookieDomain) {
+ // Don't mutate storage with empty values; fall back to router default.
+ return Boolean(defaultShouldRevalidate);
+ }
+ const storage = new NamespacedStorageManager(SESSION_STORAGE_KEY);
+ sessionValid(storage, apiHost, cookieDomain);
+ const sessionIsStale = getSessionStale(storage);
+ return sessionIsStale || defaultShouldRevalidate; Note: If you apply this, the 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
export function HydrateFallback() { | ||||||||||||||||||||||||||||||||||||||||||||
return <div style={{ padding: "32px" }}>Loading...</div>; | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
clientLoader.hydrate = true; | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like an odd place for this code, hidden between two exported functions. Which leads to question: is there a reason to define There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not understand the question? Both are needed. As the address the "lengthyness" of the root.tsx file; the file needs to have certain components/functions and loaders in it, as react-router calls the components from the Route files. We can of course cleanup and organize the 750~ lines to multiple files, if we want that, but let's make a separate task for that. |
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
const adContainerIds = ["right-column-1", "right-column-2", "right-column-3"]; | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: typos