Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/AppController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import React, {

import useLogFileStore from "../stores/logFileStore";
import useQueryStore from "../stores/queryStore";
import useUiStore from "../stores/uiStore";
import useViewStore from "../stores/viewStore";
import {TAB_NAME} from "../typings/tab";
import {HASH_PARAM_NAMES} from "../typings/url";
import {
CURSOR_CODE,
Expand All @@ -30,6 +32,8 @@ import {
const handleHashChange = () => {
updateViewHashParams();
if (updateQueryHashParams()) {
const {setActiveTabName} = useUiStore.getState();
setActiveTabName(TAB_NAME.SEARCH);
const {startQuery} = useQueryStore.getState();
startQuery();
}
Expand Down
3 changes: 3 additions & 0 deletions src/stores/logFileStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const handleQueryResults = (progress: number, results: QueryResults) => {
};


// eslint-disable-next-line max-lines-per-function
const useLogFileStore = create<LogFileState>((set) => ({
...LOG_FILE_STORE_DEFAULT,
loadFile: (fileSrc: FileSrcType, cursor: CursorType) => {
Expand Down Expand Up @@ -166,6 +167,8 @@ const useLogFileStore = create<LogFileState>((set) => ({
setUiState(UI_STATE.READY);

if (updateQueryHashParams()) {
const {setActiveTabName} = useUiStore.getState();
setActiveTabName(TAB_NAME.SEARCH);
const {startQuery} = useQueryStore.getState();
startQuery();
}
Comment on lines 169 to 174
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify no duplicate startQuery/tab-switch triggers across handlers

The AI summary notes AppController.tsx also switches to SEARCH and calls startQuery() when query hash params are present. Ensure we don’t trigger startQuery twice (once here and once in AppController) for the same navigation, which could cause duplicate work.

Consider centralising the “hash-param detected → switch to SEARCH → startQuery” flow in a single place (either AppController or this store) to avoid duplication.

Run this script to locate all call sites:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== updateQueryHashParams call sites ==="
rg -n -A 3 -B 3 $'updateQueryHashParams\\('

echo -e "\n=== startQuery call sites ==="
rg -n -A 3 -B 3 $'startQuery\\('

echo -e "\n=== setActiveTabName call sites ==="
rg -n -A 3 -B 3 $'setActiveTabName\\('

Length of output: 9733


Centralize hash-param handling to avoid duplicate searches

Both logFileStore.ts and AppController.tsx detect updateQueryHashParams(), switch to the SEARCH tab, and call startQuery(). This duplication can fire two identical queries on load.

Please consolidate this flow in one place or add a guard to prevent back-to-back triggers:

• src/stores/logFileStore.ts (lines 154–159)
• src/components/AppController.tsx (lines 33–38)

Consider moving the hash-param → tab switch → startQuery() logic entirely into AppController, or vice versa, and remove the redundant block.

🤖 Prompt for AI Agents
In src/stores/logFileStore.ts around lines 154–159, the code duplicates the
hash-param handling already implemented in src/components/AppController.tsx
(lines 33–38), causing two identical queries on load; remove or disable the
block in logFileStore.ts and centralize the hash-param →
setActiveTabName(TAB_NAME.SEARCH) → startQuery() flow in a single location
(preferably AppController), or add a guard (e.g., a boolean flag in a shared
store or check if the SEARCH tab is already active or query already started) to
prevent back-to-back triggers so only one startQuery() executes when
updateQueryHashParams() is true.

🧹 Nitpick (assertive)

Guard against redundant tab updates to avoid unnecessary re-renders

If the UI is already on the Search tab, skip dispatching setActiveTabName to reduce churn.

Apply this diff:

-                const {setActiveTabName} = useUiStore.getState();
-                setActiveTabName(TAB_NAME.SEARCH);
+                const {activeTabName, setActiveTabName} = useUiStore.getState();
+                if (TAB_NAME.SEARCH !== activeTabName) {
+                    setActiveTabName(TAB_NAME.SEARCH);
+                }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (updateQueryHashParams()) {
const {setActiveTabName} = useUiStore.getState();
setActiveTabName(TAB_NAME.SEARCH);
const {startQuery} = useQueryStore.getState();
startQuery();
}
if (updateQueryHashParams()) {
const {activeTabName, setActiveTabName} = useUiStore.getState();
if (TAB_NAME.SEARCH !== activeTabName) {
setActiveTabName(TAB_NAME.SEARCH);
}
const {startQuery} = useQueryStore.getState();
startQuery();
}
🤖 Prompt for AI Agents
In src/stores/logFileStore.ts around lines 154 to 159, guard against redundant
tab updates by reading the current active tab from useUiStore.getState() (e.g.,
const { activeTabName, setActiveTabName } = useUiStore.getState()), compare
activeTabName to TAB_NAME.SEARCH, and only call
setActiveTabName(TAB_NAME.SEARCH) when they differ; keep calling startQuery() as
before if updateQueryHashParams() returns true. Ensure you use the store's
getState() accessor without introducing side effects and preserve existing
typing.

Expand Down
Loading