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 introduces a debugging mechanism to help developers identify why a page might not be restored from the browser's back/forward cache (bfcache). When WP_DEBUG is enabled, the browser console will now display warnings detailing the reasons for bfcache invalidation, aiding in troubleshooting and optimization.

Highlights

  • Debugging: Implemented a new feature that logs reasons for bfcache invalidation to the browser console when WP_DEBUG is enabled, providing valuable insights for developers.
  • Data Export: The WP_DEBUG status is now exported from PHP to the client-side JavaScript, enabling conditional debugging behavior.
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 is currently in preview and 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 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 introduces a debugging feature for back/forward cache (bfcache) issues by logging reasons for navigation failures when WP_DEBUG is enabled. The changes involve modifications to both PHP and JavaScript files to facilitate this functionality. A suggestion has been provided to enhance the JavaScript code's readability and conciseness.

Comment on lines 81 to 93
if ( data.debug ) {
for ( const entry of performance.getEntriesByType( 'navigation' ) ) {
if (
'notRestoredReasons' in entry &&
null !== entry.notRestoredReasons
) {
window.console.warn(
'[No-cache BFCache] Reasons page navigation not restored from bfcache:',
entry.notRestoredReasons
);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This for...of loop can be simplified by directly accessing the first element of the performance.getEntriesByType('navigation') array, as it typically contains only one entry for the main document navigation. Using optional chaining (?.) can further streamline the null check for notRestoredReasons.

const [ navigationEntry ] = performance.getEntriesByType( 'navigation' );
	if ( navigationEntry?.notRestoredReasons ) {
		window.console.warn(
			'[No-cache BFCache] Reasons page navigation not restored from bfcache:',
			navigationEntry.notRestoredReasons
		);
	}

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 Good suggestion, but navigationEntry?.notRestoredReasons is problematic because TypeScript then has an error:

TS2339: Property notRestoredReasons does not exist on type PerformanceEntry

So this seems to be the better improvement:

	const [ navigationEntry ] = performance.getEntriesByType( 'navigation' );
	if (
		'notRestoredReasons' in navigationEntry &&
		null !== navigationEntry.notRestoredReasons
	) {
		window.console.warn(
			'[No-cache BFCache] Reasons page navigation not restored from bfcache:',
			navigationEntry.notRestoredReasons
		);
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

You are absolutely correct, @westonruter. My apologies for overlooking the TypeScript implications. The PerformanceEntry interface indeed does not directly expose notRestoredReasons, which is specific to PerformanceNavigationTiming.

Your proposed solution using 'notRestoredReasons' in navigationEntry && null !== navigationEntry.notRestoredReasons is an excellent and robust way to handle this. It correctly performs a runtime check for the property's existence and its non-null value, which is a common and idiomatic JavaScript pattern for dealing with potentially dynamic or less-specifically typed objects. This approach ensures type safety without requiring explicit type assertions that might obscure the underlying type hierarchy.

@westonruter westonruter merged commit d2b32e9 into main Jul 1, 2025
1 check passed
@westonruter westonruter deleted the add/debug branch July 16, 2025 03:05
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