Skip to content

Conversation

@LC43
Copy link
Contributor

@LC43 LC43 commented Sep 23, 2025

@carmoreira i removed the filter on admin_url and it stil works on basic tab + save.

was it there for a particular reason? any use case?
remove filter on admin_url

@gemini-code-assist
Copy link

Summary of Changes

Hello @LC43, 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 focuses on refining the 'remember tabs' functionality within the application. The primary goal is to enhance the reliability of tab activation by improving the frontend JavaScript logic for parsing and applying tab parameters from URLs. Concurrently, a backend PHP filter that previously modified admin URLs with tab parameters has been removed, streamlining the overall implementation and potentially resolving an unnecessary dependency or behavior.

Highlights

  • Frontend Tab Logic Rework: The JavaScript logic for remembering and activating tabs has been significantly refactored for improved robustness and error handling, particularly when parsing tab indices from URL parameters.
  • Backend Filter Removal: A PHP filter on admin_url and its associated method check_remember_tab_url have been removed, simplifying the backend handling of tab parameters.
  • Improved Tab Activation: Added a safety check in the hitTab function to ensure the target tab element exists before attempting to click it, preventing potential runtime errors.
  • Graceful Referer URL Handling: Implemented a try-catch block when processing the refererUrl to gracefully handle cases where the referer value might not form a valid URL.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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

@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 refactors the "remember tabs" feature, moving the core logic from server-side PHP to client-side JavaScript. The PHP filter on admin_url has been removed, and the JavaScript now handles updating the URL with the active tab index and restoring it on page load. This is a positive architectural change, making the UI state management self-contained on the client. The new JavaScript implementation is more robust, particularly with its improved error handling for referrer URLs. I have one suggestion to improve the logic for falling back to the current URL's tab parameter to handle an edge case correctly.

@LC43
Copy link
Contributor Author

LC43 commented Sep 23, 2025

/gemini review

Copy link

@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 refactors the 'remember tabs' feature by moving the logic entirely to the client-side JavaScript and removing the corresponding server-side PHP code. The changes in the JavaScript file make the implementation more robust by adding better error handling and defensive checks. The removal of the PHP filter and its handler simplifies the codebase. My review includes a few suggestions to further improve the robustness of the JavaScript code, particularly around URL handling to avoid potential issues with stale data and ensure correct URL parsing.

LC43 and others added 2 commits September 24, 2025 01:45
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@LC43
Copy link
Contributor Author

LC43 commented Sep 23, 2025

/gemini review

Copy link

@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 reworks the 'remember tabs' feature by moving the logic from a server-side PHP filter to client-side JavaScript. This is a positive change that centralizes the feature's logic. The new JavaScript implementation is more robust, with better error handling for URL parsing and a clearer separation of concerns between initializing the tab state and attaching event listeners.

To answer your question, the admin_url filter was indeed there to persist the active tab across page reloads that happen on saving a post. It modified the redirect URL on the server. Your new client-side approach using window.history.replaceState achieves the same result by updating the URL in the browser before the save action, making the PHP filter redundant. So its removal is correct.

I've identified a high-severity race condition in the new JavaScript initialization logic that could prevent the feature from working reliably. I've also left a medium-severity comment regarding a fragile setTimeout that could be improved for better reliability and user experience. Please see the detailed comments below.

Comment on lines 19 to 24
setTimeout(function () {
let tab = document.querySelectorAll('.csf-nav-metabox ul li a');
if (tab) {
if (tab && tab[index]) {
tab[index].click();
}
}, 1000);

Choose a reason for hiding this comment

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

medium

Using a fixed setTimeout of 1 second to trigger the tab click is brittle and can negatively impact user experience. If the tab component takes longer than 1 second to initialize, this will fail. If it's faster, the user still experiences an unnecessary 1-second delay and may see the content flash from the default tab to the target tab. A more robust approach would be to listen for an initialization event from the tab component if one is provided, or use a MutationObserver to wait for the tab elements to become available and interactive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it should be fine. this is the event that selects the active tab. it will load the preview first then the rest. right?

@LC43
Copy link
Contributor Author

LC43 commented Sep 23, 2025

AI says above, if it means anything at all:

To answer your question, the admin_url filter was indeed there to persist the active tab across page reloads that happen on saving a post. It modified the redirect URL on the server. Your new client-side approach using window.history.replaceState achieves the same result by updating the URL in the browser before the save action, making the PHP filter redundant. So its removal is correct.

@LC43
Copy link
Contributor Author

LC43 commented Sep 23, 2025

last one
/gemini review

Copy link

@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 reworks the "remember tabs" feature by moving the logic from PHP to JavaScript. The PHP admin_url filter is removed, and the JavaScript is updated to be more robust, using modern URL APIs and better error handling for parsing URLs. The changes are well-structured and improve upon the previous implementation. I have one suggestion to make the tab index parsing even more robust.

Comment on lines 50 to 52
if ( tabIndex ) {
saltusRememberTabs.hitTab( parseInt(tabIndex, 10 ) );
}

Choose a reason for hiding this comment

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

medium

The code currently calls hitTab even if parseInt results in NaN (e.g., if the tab parameter is a non-numeric string like ?tab=foo). While hitTab correctly handles an invalid index by checking tab[index], it's more robust to validate the parsed index here to prevent passing NaN further down. I suggest adding a check for isNaN after parsing the tab index.

	if ( tabIndex ) {
		const tabIndexInt = parseInt(tabIndex, 10);
		if ( !isNaN(tabIndexInt) ) {
			saltusRememberTabs.hitTab(tabIndexInt);
		}
	}

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