Skip to content

[ENGG-4757] fix: Not able to quit desktop app#4171

Merged
Aarushsr12 merged 2 commits intomasterfrom
ENGG-4757
Jan 15, 2026
Merged

[ENGG-4757] fix: Not able to quit desktop app#4171
Aarushsr12 merged 2 commits intomasterfrom
ENGG-4757

Conversation

@Aarushsr12
Copy link
Contributor

@Aarushsr12 Aarushsr12 commented Jan 14, 2026

Root Cause Analysis: First Startup Quit Bug

Issue

On first startup, clicking the close button (X) causes the app to hang instead of quitting. Works normally on subsequent startups.

Root Cause

The initiate-app-close IPC handler registration had a missing dependency in its useEffect, causing it to never register when appMode changed from the default "EXTENSION" to "DESKTOP".

Technical Details

Flow on first startup:

  1. User clicks close → Main process sends "initiate-app-close" message
  2. Handler in AppModeInitializer.js (line 215) should catch this and navigate to quit page
  3. BUG: Handler never registered because:
    • useEffect runs with initial appMode = "EXTENSION" (default value from Redux)
    • if (appMode === DESKTOP) condition fails → handler not registered
    • Later useEffect (line 299) updates appMode to "DESKTOP"
    • Original useEffect doesn't re-run (empty dependency array [])
  4. Message is lost

Why it worked on 2nd+ startups:

  • appMode persisted from previous session as "DESKTOP"
  • useEffect condition passes immediately
  • Handlers registered successfully

Fix

Added appMode to the useEffect dependency array:
}, [appMode]); // Changed from []

@linear
Copy link

linear bot commented Jan 14, 2026

@Aarushsr12 Aarushsr12 requested a review from wrongsahil January 14, 2026 11:56
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2026

Walkthrough

The AppModeInitializer useEffect that registers IPC handlers for desktop deep linking and app-close initiation was changed to include a cleanup function that unregisters the "deeplink-handler" and "initiate-app-close" events on unmount or dependency change. The effect's dependency array was updated from [] to include appMode, causing the effect to re-run when appMode changes. No public/exported signatures were modified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is entirely missing. The template requires multiple sections including summary of changes, demo video, checklist, and test instructions. Add a complete pull request description following the template, including a summary of changes, demo video or explanation of why it's not applicable, completed checklist, and test instructions.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly references the issue ENGG-4757 and identifies the main change as fixing the inability to quit the desktop app, which aligns with the code change adding cleanup for app close event handlers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5cad46a and 1483bf9.

📒 Files selected for processing (1)
  • app/src/hooks/AppModeInitializer.js
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: rohanmathur91
Repo: requestly/requestly PR: 4000
File: app/src/features/apiClient/slices/multiWorkspaceView/helpers/ApiClientContextRegistry/hooks.ts:6-14
Timestamp: 2025-12-11T06:43:01.328Z
Learning: In app/src/features/apiClient/slices/multiWorkspaceView/helpers/ApiClientContextRegistry/hooks.ts, the useApiClientFeatureContext hook uses useMemo without reactivity intentionally. Contexts are expected to be registered before component mount, and reactivity to registry updates is not needed.
📚 Learning: 2025-12-11T06:43:01.328Z
Learnt from: rohanmathur91
Repo: requestly/requestly PR: 4000
File: app/src/features/apiClient/slices/multiWorkspaceView/helpers/ApiClientContextRegistry/hooks.ts:6-14
Timestamp: 2025-12-11T06:43:01.328Z
Learning: In app/src/features/apiClient/slices/multiWorkspaceView/helpers/ApiClientContextRegistry/hooks.ts, the useApiClientFeatureContext hook uses useMemo without reactivity intentionally. Contexts are expected to be registered before component mount, and reactivity to registry updates is not needed.

Applied to files:

  • app/src/hooks/AppModeInitializer.js
🔇 Additional comments (1)
app/src/hooks/AppModeInitializer.js (1)

214-229: LGTM! Proper cleanup pattern for IPC event handlers.

The cleanup function correctly unregisters the IPC events on unmount or when appMode changes. The cleanup is appropriately scoped inside the conditional block, ensuring it only runs when handlers were actually registered.

One observation for future consideration: other useEffects in this file (lines 85-212 and 243-279) also register IPC events without cleanup functions. While they have different lifecycle requirements (the first runs conditionally on isBackgroundProcessActive, the second has an empty dependency array), you may want to audit them for similar cleanup needs if issues arise.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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.

@Aarushsr12 Aarushsr12 requested a review from nsrCodes January 14, 2026 11:57
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/src/hooks/AppModeInitializer.js (1)

214-224: Add cleanup function to prevent duplicate IPC event handlers.

The dependency array change from [] to [appMode] correctly ensures handlers register once appMode becomes DESKTOP. However, this creates duplicate handler registrations: each time appMode changes after initial registration, the effect re-runs and registers the handlers again without removing the previous ones.

The codebase has window.RQ.DESKTOP.SERVICES.IPC.unregisterEvent() available (used in DesktopBackgroundService.ts), so cleanup is required:

🔧 Required cleanup pattern
 useEffect(() => {
   if (appMode === GLOBAL_CONSTANTS.APP_MODES.DESKTOP) {
     window.RQ.DESKTOP.SERVICES.IPC.registerEvent("deeplink-handler", (payload) => {
       navigate(payload);
     });
     window.RQ.DESKTOP.SERVICES.IPC.registerEvent("initiate-app-close", () => {
       navigate(PATHS.DESKTOP.QUIT.ABSOLUTE);
     });
+
+    return () => {
+      window.RQ.DESKTOP.SERVICES.IPC.unregisterEvent("deeplink-handler");
+      window.RQ.DESKTOP.SERVICES.IPC.unregisterEvent("initiate-app-close");
+    };
   }
   // eslint-disable-next-line react-hooks/exhaustive-deps
 }, [appMode]);
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14ffec1 and 5cad46a.

📒 Files selected for processing (1)
  • app/src/hooks/AppModeInitializer.js
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: rohanmathur91
Repo: requestly/requestly PR: 4000
File: app/src/features/apiClient/slices/multiWorkspaceView/helpers/ApiClientContextRegistry/hooks.ts:6-14
Timestamp: 2025-12-11T06:43:01.328Z
Learning: In app/src/features/apiClient/slices/multiWorkspaceView/helpers/ApiClientContextRegistry/hooks.ts, the useApiClientFeatureContext hook uses useMemo without reactivity intentionally. Contexts are expected to be registered before component mount, and reactivity to registry updates is not needed.
Learnt from: nafees87n
Repo: requestly/requestly PR: 3417
File: app/src/hooks/workspaceFetcher/useWorkspaceFetcher.ts:4-7
Timestamp: 2025-08-20T11:23:01.896Z
Learning: In useFetchTeamWorkspaces hook, activeWorkspaceId should not be included in the effect dependency array to avoid re-subscription on every workspace change, as per user's preference.
📚 Learning: 2025-12-11T06:43:01.328Z
Learnt from: rohanmathur91
Repo: requestly/requestly PR: 4000
File: app/src/features/apiClient/slices/multiWorkspaceView/helpers/ApiClientContextRegistry/hooks.ts:6-14
Timestamp: 2025-12-11T06:43:01.328Z
Learning: In app/src/features/apiClient/slices/multiWorkspaceView/helpers/ApiClientContextRegistry/hooks.ts, the useApiClientFeatureContext hook uses useMemo without reactivity intentionally. Contexts are expected to be registered before component mount, and reactivity to registry updates is not needed.

Applied to files:

  • app/src/hooks/AppModeInitializer.js
🧬 Code graph analysis (1)
app/src/hooks/AppModeInitializer.js (16)
app/src/features/sessionBook/components/PermissionError/index.js (1)
  • appMode (18-18)
app/src/layouts/DashboardLayout/DashboardContent.js (1)
  • appMode (44-44)
app/src/hooks/DbListenerInit/DBListeners.js (1)
  • appMode (21-21)
app/src/components/user/Teams/CreateWorkspace/CreateWorkspace.js (1)
  • appMode (27-27)
app/src/features/settings/components/Profile/ManageTeams/TeamViewer/SwitchWorkspaceButton/index.jsx (1)
  • appMode (15-15)
app/src/components/features/rules/ChangeRuleGroupModal/index.js (1)
  • appMode (36-36)
app/src/components/features/rules/RenameGroupModal/index.js (1)
  • appMode (27-27)
app/src/components/features/rules/RuleBuilder/RuleBuilder.js (1)
  • appMode (58-58)
app/src/components/features/rules/UngroupOrDeleteRulesModal/index.js (1)
  • appMode (26-26)
app/src/hooks/FeatureUsageEvent.js (1)
  • appMode (15-15)
app/src/views/features/sessions/ConfigurationPage/ConfigurationPage.js (1)
  • appMode (50-50)
app/src/layouts/DashboardLayout/MenuHeader/HeaderUser.jsx (1)
  • appMode (41-41)
app/src/features/rules/modals/ImportRulesModal/index.jsx (1)
  • appMode (45-45)
app/src/views/features/rules/RuleEditor/components/Header/ActionButtons/CreateRuleButton/index.jsx (1)
  • appMode (113-113)
app/src/components/sections/Navbars/NavbarRightContent/DesktopAppProxyInfo/index.jsx (1)
  • appMode (16-16)
app/src/components/misc/SignInViaEmailLink/SignInViaEmailLink.js (1)
  • appMode (40-40)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@Aarushsr12 Aarushsr12 linked an issue Jan 15, 2026 that may be closed by this pull request
4 tasks
@Aarushsr12 Aarushsr12 merged commit 00631e2 into master Jan 15, 2026
3 checks passed
@Aarushsr12 Aarushsr12 mentioned this pull request Jan 15, 2026
4 tasks
@Aarushsr12 Aarushsr12 linked an issue Jan 15, 2026 that may be closed by this pull request
4 tasks
@Aarushsr12 Aarushsr12 mentioned this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants