-
Notifications
You must be signed in to change notification settings - Fork 1
Fix/rework remember tabs #50
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: dev
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
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.
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.
|
/gemini review |
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.
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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
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.
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.
| setTimeout(function () { | ||
| let tab = document.querySelectorAll('.csf-nav-metabox ul li a'); | ||
| if (tab) { | ||
| if (tab && tab[index]) { | ||
| tab[index].click(); | ||
| } | ||
| }, 1000); |
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.
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.
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.
it should be fine. this is the event that selects the active tab. it will load the preview first then the rest. right?
|
AI says above, if it means anything at all:
|
|
last one |
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.
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.
| if ( tabIndex ) { | ||
| saltusRememberTabs.hitTab( parseInt(tabIndex, 10 ) ); | ||
| } |
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.
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);
}
}
@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