Skip to content

Conversation

@TalexDreamSoul
Copy link
Contributor

@TalexDreamSoul TalexDreamSoul commented Jan 26, 2026

Problem

CoreBox does not properly shrink to minimum height when:

  1. Recommendation is disabled or times out
  2. Input is cleared but window stays expanded
  3. No results are available but window doesn't collapse

This creates a poor user experience where the window remains unnecessarily large.

Root Cause Analysis

Issue 1: Recommendation Timeout Not Triggering Collapse

Location: useSearch.ts - recommendation timeout handler

The timeout handler would call resetSearchState() but not explicitly trigger a collapse, leaving the window in an expanded state.

Issue 2: resetSearchState Not Triggering Collapse

Location: useSearch.ts - resetSearchState() function

When resetting search state, the function would dispatch a layout refresh event but not explicitly trigger collapse when input is empty.

Issue 3: Height Calculation Not Forcing Minimum

Location: useResize.ts - sendLayoutUpdate() function

The height calculation would use calculateDesiredHeight() even when there are no results and no pending operations, instead of forcing minimum height.

Issue 4: Waiting State Not Preserving Collapsed State

Location: core-box/index.ts - applyLayoutUpdate() function

When waiting for data (loading/recommendation), the function would keep current size but not check if already collapsed, potentially expanding unnecessarily.

Solution

Fix 1: Explicit Collapse on Recommendation Timeout

recommendationTimeoutId = setTimeout(() => {
  if (recommendationPending.value && searchResults.value.length === 0) {
    recommendationPending.value = false
    loading.value = false
    resetSearchState()
    // ✅ Explicitly trigger collapse when recommendation times out
    transport.send(CoreBoxEvents.ui.expand, { mode: 'collapse' }).catch(() => {})
  }
  recommendationTimeoutId = null
}, RECOMMENDATION_TIMEOUT_MS)

Fix 2: Trigger Collapse in resetSearchState

const resetSearchState = (): void => {
  // ... existing reset logic
  
  // ✅ Trigger collapse if no input and no results
    transport.send(CoreBoxEvents.ui.expand, { mode: 'collapse' }).catch(() => {})
  }
}

Fix 3: Force Minimum Height When Appropriate

// ✅ When no results and not waiting for data, force minimum height
let height: number
  height = MIN_HEIGHT
} else {
  height = calculateDesiredHeight(resultCount)
}

Fix 4: Preserve Collapsed State When Waiting

if (resultCount === 0 && (loading || recommendationPending)) {
  // ✅ If already collapsed, keep it collapsed
  if (coreBoxManager.isCollapsed) {
    return
  }
  // Not collapsed yet, keep current size to avoid jitter
  return
}

Changes

Modified Files

  1. useSearch.ts

    • Added explicit collapse trigger in recommendation timeout handler
    • Added collapse trigger in resetSearchState() when input is empty
  2. useResize.ts

    • Force minimum height when no results and not waiting for data
    • Improved height calculation logic
  3. core-box/index.ts

    • Preserve collapsed state when waiting for data
    • Added comment clarifying strict collapse condition

Testing

The fix should be tested with:

  1. Recommendation disabled: Clear input → window should shrink
  2. Recommendation timeout: Wait 400ms with no results → window should shrink
  3. Clear input: Type then clear → window should shrink immediately
  4. No results: Search with no matches → window should shrink

Impact

  • ✅ Improves user experience with proper window sizing
  • ✅ Reduces visual clutter when no content is displayed
  • ✅ Makes CoreBox behavior more predictable and consistent
  • ✅ No breaking changes to existing functionality

Related Issues

This PR addresses the CoreBox shrink issue reported by users.

Summary by CodeRabbit

Bug Fixes

  • Improved empty result state handling to prevent layout jitter when results are loading or pending.
  • Fixed height calculation for empty searches to use consistent minimum sizing instead of content-based sizing.
  • Enhanced collapse behavior during search reset and recommendation timeout scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

- Fix recommendation timeout handling to explicitly trigger collapse
- Improve resetSearchState to trigger collapse when input is empty
- Force minimum height when no results and not waiting for data
- Keep collapsed state when waiting for data if already collapsed

This fix addresses the issue where CoreBox would not shrink when:
1. Recommendation is disabled or times out
2. Input is cleared but window stays expanded
3. No results are available but window doesn't collapse

The changes ensure CoreBox properly shrinks to minimum height when
there are no results, no input, and no pending operations.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

These changes introduce collapse/expand behavior to a search box component when results are empty. The main process validates collapsed state preservation, the resize hook conditionally applies minimum height, and the search hook triggers collapse on input reset and recommendation timeout.

Changes

Cohort / File(s) Summary
Collapse/Expand Logic
apps/core-app/src/main/modules/box-tool/core-box/index.ts, apps/core-app/src/renderer/src/modules/box/adapter/hooks/useSearch.ts, apps/core-app/src/renderer/src/modules/box/adapter/hooks/useResize.ts
Added strict collapse conditions when results are empty and recommendations are pending. Main logic prevents jitter by preserving collapsed state. Search hook triggers collapse on reset (empty input) and when recommendation timeout occurs. Resize hook forces MIN_HEIGHT for zero-result scenarios instead of calculating from content.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A rabbit's tale of the collapsing box:
When searches yield not a single result,
Down folds the container with graceful exult,
Recommendations pending, patience so sweet—
Hide and reveal make the dance complete! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing and improving CoreBox shrink behavior when recommendations are not available or pending.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/core-app/src/renderer/src/modules/box/adapter/hooks/useResize.ts`:
- Around line 76-82: The brace-style lint error is caused by the `else` being on
the same line as the closing brace in the conditional that sets `height` (using
`resultCount`, `isLoading`, `isRecommendationPending`, `MIN_HEIGHT`, and
`calculateDesiredHeight`); fix it by moving `else` to its own line and
formatting the if/else block to match the project's brace-style (i.e., place the
closing brace on its own line followed by a newline then `else`), ensuring the
`height` assignment logic remains the same in `useResize.ts`.
🧹 Nitpick comments (1)
apps/core-app/src/renderer/src/modules/box/adapter/hooks/useSearch.ts (1)

364-370: Avoid duplicate collapse dispatch on timeout.

resetSearchState() now collapses when input is empty, so the extra CoreBoxEvents.ui.expand send here triggers redundant IPC. Consider removing or gating it.

♻️ Proposed simplification
-          // Explicitly trigger collapse when recommendation times out
-          transport.send(CoreBoxEvents.ui.expand, { mode: 'collapse' }).catch(() => {})

Comment on lines +76 to +82
// When no results and not waiting for data, force minimum height
let height: number
if (resultCount === 0 && !isLoading && !isRecommendationPending) {
height = MIN_HEIGHT
} else {
height = calculateDesiredHeight(resultCount)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix ESLint brace-style violation.

ESLint reports style/brace-style at Line 80 because else is on the same line as the closing brace. Adjust to the configured style to avoid lint failures.

🧹 Suggested fix
-    } else {
+    }
+    else {
       height = calculateDesiredHeight(resultCount)
     }
📝 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
// When no results and not waiting for data, force minimum height
let height: number
if (resultCount === 0 && !isLoading && !isRecommendationPending) {
height = MIN_HEIGHT
} else {
height = calculateDesiredHeight(resultCount)
}
// When no results and not waiting for data, force minimum height
let height: number
if (resultCount === 0 && !isLoading && !isRecommendationPending) {
height = MIN_HEIGHT
}
else {
height = calculateDesiredHeight(resultCount)
}
🧰 Tools
🪛 ESLint

[error] 80-80: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)

🤖 Prompt for AI Agents
In `@apps/core-app/src/renderer/src/modules/box/adapter/hooks/useResize.ts` around
lines 76 - 82, The brace-style lint error is caused by the `else` being on the
same line as the closing brace in the conditional that sets `height` (using
`resultCount`, `isLoading`, `isRecommendationPending`, `MIN_HEIGHT`, and
`calculateDesiredHeight`); fix it by moving `else` to its own line and
formatting the if/else block to match the project's brace-style (i.e., place the
closing brace on its own line followed by a newline then `else`), ensuring the
`height` assignment logic remains the same in `useResize.ts`.

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