Skip to content

fix: Prevent duplicate page loads on rapid keyboard shortcut use (fixes #198). #200

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

Merged
merged 7 commits into from
Mar 17, 2025

Conversation

Henry8192
Copy link
Collaborator

@Henry8192 Henry8192 commented Mar 5, 2025

Description

Fixes #198.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  1. Open log viewer and load a log file using the provided link.
  2. Set the page size to 10000 or less, open the console.
  3. Press and hold Ctrl/ Cmd + [ and observe that each page gets loaded only once.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Improved navigation stability by ensuring that rapid page requests are paused during high-speed loading, preventing accidental multiple transitions.
    • Added a safeguard to prevent navigation actions when the UI is not ready, enhancing overall control flow.

@Henry8192 Henry8192 requested a review from a team as a code owner March 5, 2025 18:18
Copy link

coderabbitai bot commented Mar 5, 2025

Walkthrough

This PR modifies the loadPageByAction function in the StateContextProvider component. A new conditional check is added to detect when the UI state is UI_STATE.READY. If this condition is not met, a warning is logged, and the function returns early, preventing further navigation actions during an inappropriate UI state. Additionally, a redundant blank line is removed for improved code readability.

Changes

File Change Summary
src/contexts/StateContextProvider.tsx Added a conditional check in loadPageByAction to log a warning and return early if the UI is not in UI_STATE.READY; removed an extra blank line.

Sequence Diagram(s)

sequenceDiagram
    participant UI as User Interface
    participant SCP as StateContextProvider
    participant Console as Console

    UI->>SCP: Trigger navigation action
    SCP->>SCP: Check UI state (READY?)
    alt UI_STATE is not READY
        SCP->>Console: Log warning "Page load in progress"
        SCP-->>UI: Return early (skip navigation)
    else
        SCP->>SCP: Set UI state to READY
        SCP->>Other: Continue with navigation actions
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Lock keybindings during page loading to prevent duplicate loads (198)

Possibly related PRs

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2dbfded and b966521.

📒 Files selected for processing (1)
  • src/contexts/StateContextProvider.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/contexts/StateContextProvider.tsx

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Henry8192 Henry8192 requested a review from junhaoliao March 5, 2025 18:20
@Henry8192 Henry8192 changed the title Fix(StateContext): Duplicate load page when using loadPage keyboard shortcut (fixes #198). fix(StateContext): Duplicate load page when using loadPage keyboard shortcut (fixes #198). Mar 5, 2025
@junhaoliao junhaoliao requested a review from davemarco March 5, 2025 20:21
Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

The descriptions in Conventional Messages are usually in imperative mood.

for the PR title, how about:

fix: Prevent duplicate page loads on rapid keyboard shortcut use (fixes #198).

@davemarco
Copy link
Contributor

I looked briefly

Couple questions.

  • does it make sense to lift the state check to here. Not sure if better or not but will block all actions not just page load.
  • Consider checking if state != ready, vs state == fastloading

@Henry8192 Henry8192 changed the title fix(StateContext): Duplicate load page when using loadPage keyboard shortcut (fixes #198). fix: Prevent duplicate page loads on rapid keyboard shortcut use (fixes #198). Mar 13, 2025
@Henry8192
Copy link
Collaborator Author

  • does it make sense to lift the state check to here. Not sure if better or not but will block all actions not just page load.

If you mean add the state check right after the first four case checks, I believe it is identical right?

  • Consider checking if state != ready, vs state == fastloading

Good one.

@davemarco
Copy link
Contributor

davemarco commented Mar 13, 2025

If you mean add the state check right after the first four case checks, I believe it is identical right?

I think if just 4 then identical, but maybe we want to block all actions.
like handleCopyLogEventAction(editor, beginLineNumToLogEventNumRef.current); might have some weird behavior with log level filter

anyways we'll see what @junhaoliao thinks

@Henry8192
Copy link
Collaborator Author

ah, I see what you mean now. I agree with that then, it would make a lot of sense for editors to check uiStates before performing any actions.

@Henry8192
Copy link
Collaborator Author

But what the cons for this approach is that whenever uiState changes, this callback function gets re-rendered. Do we want to do that?

@davemarco
Copy link
Contributor

But what the cons for this approach is that whenever uiState changes, this callback function gets re-rendered. Do we want to do that?

It's probably fine, but if you want you can test that nothing really slow happens. Or you can try and just pass the uiState ref instead?

@junhaoliao
Copy link
Member

junhaoliao commented Mar 15, 2025

  • i agree it's better to check against READY

  • regarding the modification in loadPageByAction:

    • whether we block actions or not in the editor, i believe we want to constrain the request queue to only allow one page-load request at a time (unless you mean we want to queue page load requests?). that's to say, modifying loadPageByAction is the minimum we want to do.
    • that said, i believe we can move the check after we know the action is not a RELOAD one. a RELOAD action reloads the file by calling loadFile, which destroys the existing worker and as a result drops all previous requests. since loading a file is the end result and any previous requests won't cause confusion / conflicts, i think it's better to respect the RELOAD action call.
  • regarding whether we want to prevent other editor actions when the app is loading:

    • probably not. currently we don't disable inputs on the editor when the app is loading, which means users are allowed to select / copy any text when loading. if we want to disable those editor actions, which for example includes copying some log event, we might want to disable the other inputs as well for consistency. and that's probably not what we want

@Henry8192 Henry8192 merged commit 5d30e7a into y-scope:main Mar 17, 2025
3 checks passed
@Henry8192 Henry8192 deleted the duplicate-loadPage-fix branch March 17, 2025 14:40
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.

Frequent prev_page or next_page keybinding request would trigger duplicate loadPage
4 participants