Skip to content

Conversation

@westonruter
Copy link
Owner

No description provided.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @westonruter, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the existing cache invalidation mechanism by extending its scope to cover HTTP cache, in addition to the browser's back/forward cache (bfcache). The core change involves a client-side check that compares a session token embedded in the HTML with the current user's session cookie, ensuring that stale authenticated pages are reloaded upon restoration from any cache.

Highlights

  • HTTP Cache Invalidation: Implemented a client-side mechanism to invalidate pages restored from HTTP cache by comparing an initialSessionToken (passed from PHP in the HTML) with the current user's session cookie. If they don't match, the page is reloaded.
  • Enhanced Page Reload Logic: Introduced a dedicated invalidateCache() JavaScript function that visually clears the page content and forces a full reload when a session token mismatch is detected.
  • Internationalized Debugging & Feedback: Added internationalized strings for console logging and user feedback during the cache invalidation process.
  • Infinite Reload Prevention: Incorporated a query parameter (nocache_bfcache_invalidated_page_reloaded) to prevent scenarios where a page might repeatedly be deemed stale and trigger continuous reloads.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively implements HTTP cache invalidation by passing an initial session token in the HTML and comparing it against the session token cookie on page load. The logic is sound, and it includes important safeguards like protection against infinite reloads.

My review highlights a minor typo in a translatable string and suggests a safer approach for DOM manipulation during cache invalidation to improve robustness. Overall, the changes are well-structured and successfully achieve the PR's goal.

document.body.style.opacity = '0.0';

// Immediately clear out the contents of the page since otherwise the authenticated content will appear while the page reloads.
document.documentElement.innerHTML = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using document.documentElement.innerHTML = '' is very aggressive as it clears the entire <html> element's content, including the <head> and the currently executing script. This can lead to unpredictable behavior and is generally unsafe. It also removes the <body> element on which you just set the opacity, so a new <body> is created by the browser without this style.

A safer alternative is to clear only the <body>. This achieves the goal of removing visible stale content without being overly destructive.

Suggested change
document.documentElement.innerHTML = '';
document.body.innerHTML = '';

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gemini-code-assist Complete destruction is intended, as it needs to also remove any stylesheets or content in the HEAD.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification, @westonruter. Your explanation makes perfect sense. If the intent is indeed to perform a complete destruction of the page's loaded content, including stylesheets and other elements within the <head> that might persist or affect the display before a full reload, then document.documentElement.innerHTML = '' is the correct and most effective approach to achieve that level of invalidation. My initial suggestion was based on a more common scenario of clearing only visible body content, but your requirement for comprehensive removal necessitates this more aggressive method.

westonruter and others added 2 commits July 22, 2025 20:00
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@westonruter westonruter merged commit 807529e into main Jul 23, 2025
2 checks passed
@westonruter westonruter deleted the fix/http-cache-invalidation branch July 23, 2025 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants