Skip to content

[WEB-4693] fix: remove initial load flicker on auto-archive and auto-close automation page#7578

Merged
pushya22 merged 3 commits intopreviewfrom
fix-automation-page-flicker
Aug 13, 2025
Merged

[WEB-4693] fix: remove initial load flicker on auto-archive and auto-close automation page#7578
pushya22 merged 3 commits intopreviewfrom
fix-automation-page-flicker

Conversation

@prateekshourya29
Copy link
Member

@prateekshourya29 prateekshourya29 commented Aug 13, 2025

Description

Updated the ToggleSwitch components in both auto-archive-automation.tsx and auto-close-automation.tsx to resolve the flickering issue that occurred during the initial page load.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

Here are the updated release notes:

  • Bug Fixes

    • Auto-archive and auto-close toggles now default to off when settings are unset.
    • Prevents unintended display of duration/details sections when project data is missing.
    • Ensures UI doesn't show active automation states based on undefined values.
  • Refactor

    • Consolidated status logic for auto-archive and auto-close to ensure consistent behavior and simpler maintenance.

@prateekshourya29 prateekshourya29 self-assigned this Aug 13, 2025
@prateekshourya29 prateekshourya29 added the 🐛bug Something isn't working label Aug 13, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

Walkthrough

Added memoized helpers to compute active state in two automation components (auto-archive and auto-close); replaced inline checks with these helpers so undefined project details are treated as inactive. No exported APIs or public signatures changed.

Changes

Cohort / File(s) Summary
Automation: auto-archive
apps/web/core/components/automation/auto-archive-automation.tsx
Added useMemo-based autoArchiveStatus helper; replaced inline currentProjectDetails?.archive_in !== 0 checks with autoArchiveStatus for ToggleSwitch value and conditional rendering; undefined details now render as inactive.
Automation: auto-close
apps/web/core/components/automation/auto-close-automation.tsx
Added useMemo-based autoCloseStatus helper; replaced inline currentProjectDetails?.close_in !== 0 checks with autoCloseStatus for ToggleSwitch value and conditional rendering; undefined details now render as inactive.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant UI as Automation Component
  participant M as useMemo helper

  U->>UI: view component / toggle
  UI->>M: compute status from currentProjectDetails
  M-->>UI: boolean (false if details undefined or 0)
  UI->>UI: render ToggleSwitch (value = status)
  alt status true
    UI->>UI: render details panel
  else status false
    UI->>UI: hide details panel
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

🌐frontend

Suggested reviewers

  • sriramveeraghanta
  • anmolsinghbhatia

Poem

I twitch my whiskers at toggles two,
I memo their moods, decide true/false anew.
When details vanish into burrowed night,
I set the switches gentle and light.
Hop—clean states, and everything's bright. 🥕🐇


📜 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 036e229 and 37a64a6.

📒 Files selected for processing (2)
  • apps/web/core/components/automation/auto-archive-automation.tsx (4 hunks)
  • apps/web/core/components/automation/auto-close-automation.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/core/components/automation/auto-close-automation.tsx
  • apps/web/core/components/automation/auto-archive-automation.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
  • GitHub Check: Build and lint web apps
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-automation-page-flicker

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@makeplane
Copy link

makeplane bot commented Aug 13, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

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: 2

🔭 Outside diff range comments (2)
apps/web/core/components/automation/auto-archive-automation.tsx (1)

80-95: Wrap onChange in try/catch and track failures

Currently, failures in handleChange skip tracking altogether. Wrap with try/catch to record both outcomes and avoid silent failures.

-            onChange={async () => {
-              if (currentProjectDetails?.archive_in === 0) {
-                await handleChange({ archive_in: 1 });
-              } else {
-                await handleChange({ archive_in: 0 });
-              }
-              captureElementAndEvent({
-                element: {
-                  elementName: PROJECT_SETTINGS_TRACKER_ELEMENTS.AUTOMATIONS_ARCHIVE_TOGGLE_BUTTON,
-                },
-                event: {
-                  eventName: PROJECT_SETTINGS_TRACKER_EVENTS.auto_archive_workitems,
-                  state: "SUCCESS",
-                },
-              });
-            }}
+            onChange={async () => {
+              try {
+                if (currentProjectDetails?.archive_in === 0) {
+                  await handleChange({ archive_in: 1 });
+                } else {
+                  await handleChange({ archive_in: 0 });
+                }
+                captureElementAndEvent({
+                  element: {
+                    elementName: PROJECT_SETTINGS_TRACKER_ELEMENTS.AUTOMATIONS_ARCHIVE_TOGGLE_BUTTON,
+                  },
+                  event: {
+                    eventName: PROJECT_SETTINGS_TRACKER_EVENTS.auto_archive_workitems,
+                    state: "SUCCESS",
+                  },
+                });
+              } catch (error) {
+                captureElementAndEvent({
+                  element: {
+                    elementName: PROJECT_SETTINGS_TRACKER_ELEMENTS.AUTOMATIONS_ARCHIVE_TOGGLE_BUTTON,
+                  },
+                  event: {
+                    eventName: PROJECT_SETTINGS_TRACKER_EVENTS.auto_archive_workitems,
+                    state: "ERROR",
+                  },
+                });
+              }
+            }}
apps/web/core/components/automation/auto-close-automation.tsx (1)

107-122: Wrap onChange in try/catch and track failures

Capture both success and error states to improve observability and avoid silent failures.

-            onChange={async () => {
-              if (currentProjectDetails?.close_in === 0) {
-                await handleChange({ close_in: 1, default_state: defaultState });
-              } else {
-                await handleChange({ close_in: 0, default_state: null });
-              }
-              captureElementAndEvent({
-                element: {
-                  elementName: PROJECT_SETTINGS_TRACKER_ELEMENTS.AUTOMATIONS_CLOSE_TOGGLE_BUTTON,
-                },
-                event: {
-                  eventName: PROJECT_SETTINGS_TRACKER_EVENTS.auto_close_workitems,
-                  state: "SUCCESS",
-                },
-              });
-            }}
+            onChange={async () => {
+              try {
+                if (currentProjectDetails?.close_in === 0) {
+                  await handleChange({ close_in: 1, default_state: defaultState });
+                } else {
+                  await handleChange({ close_in: 0, default_state: null });
+                }
+                captureElementAndEvent({
+                  element: {
+                    elementName: PROJECT_SETTINGS_TRACKER_ELEMENTS.AUTOMATIONS_CLOSE_TOGGLE_BUTTON,
+                  },
+                  event: {
+                    eventName: PROJECT_SETTINGS_TRACKER_EVENTS.auto_close_workitems,
+                    state: "SUCCESS",
+                  },
+                });
+              } catch (error) {
+                captureElementAndEvent({
+                  element: {
+                    elementName: PROJECT_SETTINGS_TRACKER_ELEMENTS.AUTOMATIONS_CLOSE_TOGGLE_BUTTON,
+                  },
+                  event: {
+                    eventName: PROJECT_SETTINGS_TRACKER_EVENTS.auto_close_workitems,
+                    state: "ERROR",
+                  },
+                });
+              }
+            }}
🧹 Nitpick comments (4)
apps/web/core/components/automation/auto-archive-automation.tsx (1)

97-97: Disable toggle while project details are not loaded

Prevents firing handleChange against incomplete data and aligns with the “inactive while undefined” intent.

-            disabled={!isAdmin}
+            disabled={!isAdmin || !currentProjectDetails}
apps/web/core/components/automation/auto-close-automation.tsx (3)

124-124: Disable toggle while project details are not loaded

Prevents updates against incomplete data and aligns with the inactive-until-defined UX.

-            disabled={!isAdmin}
+            disabled={!isAdmin || !currentProjectDetails}

166-166: Typo in className: remove stray “ppy” utility

“ppy” is not a valid Tailwind class and is likely a leftover. It could cause confusion.

-                <div className="ppy sm:py-10 flex w-full items-center justify-between gap-2 px-5 py-4">
+                <div className="sm:py-10 flex w-full items-center justify-between gap-2 px-5 py-4">

108-112: Verify default_state behavior when enabling auto-close

When enabling, default_state is set to defaultState, which may be null if projectStates haven’t loaded. Confirm backend allows null here or defer toggling until defaultState is known. If not allowed, guard or compute a safe fallback.

Possible guards:

  • Disable the toggle when enabling if defaultState is null.
  • Or, compute a fallback cancelled state once projectStates load before allowing enable.

Also applies to: 171-173

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 34c6047 and d5220e9.

📒 Files selected for processing (2)
  • apps/web/core/components/automation/auto-archive-automation.tsx (3 hunks)
  • apps/web/core/components/automation/auto-close-automation.tsx (3 hunks)
🔇 Additional comments (2)
apps/web/core/components/automation/auto-archive-automation.tsx (1)

79-79: LGTM: Centralized active-state check removes initial flicker

Using a single helper for both the ToggleSwitch value and conditional rendering is clearer and fixes the undefined→true flicker.

Also applies to: 102-102

apps/web/core/components/automation/auto-close-automation.tsx (1)

106-106: LGTM: Centralized active-state check removes initial flicker

Consistent with auto-archive; improves readability and correctness on initial load.

Also applies to: 129-129

);

const getAutoArchiveStatus = () => {
if (currentProjectDetails === undefined || currentProjectDetails.archive_in === undefined) return false;
Copy link
Member

Choose a reason for hiding this comment

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

There's no need of this check.

Copy link
Member Author

Choose a reason for hiding this comment

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

It’s required because this was the cause of the flicker. We’re directly comparing currentProjectDetails?.archive_in !== 0 and rendering the details, which is true even if the archive_in is undefined.

Copy link
Member

Choose a reason for hiding this comment

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

What I mean is, there's no need to check for currentProjectDetails === undefined

Copy link
Member Author

Choose a reason for hiding this comment

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

It will remain the same. Without that, we’ll check currentProjectDetails?.archive_in === undefined with optional chaining, which essentially combines both these conditions.

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

🔭 Outside diff range comments (1)
apps/web/core/components/automation/auto-close-automation.tsx (1)

123-125: Disable the toggle while project details are loading

Avoid invoking handleChange before the project is loaded (could lead to unintended updates when currentProjectDetails is undefined).

Apply this diff:

-            disabled={!isAdmin}
+            disabled={!isAdmin || !currentProjectDetails}
♻️ Duplicate comments (3)
apps/web/core/components/automation/auto-close-automation.tsx (3)

106-106: Value prop wiring is correct; ensure the memo above updates promptly

value={autoCloseStatus} is correct. With the fix to the memo dependencies/null-safety above, the toggle will reflect store changes immediately.

Please verify that toggling updates the UI instantly (no extra render or stale state).


129-129: Conditional details rendering depends on the same autoCloseStatus fix

This usage is fine and should remove the initial flicker. It will still rely on the corrected autoCloseStatus to avoid stale visibility.


78-82: Fix stale memoization and add null-safety for autoCloseStatus

  • Dependency on the whole currentProjectDetails object can keep the memo stale if MobX mutates the same object reference (common pattern).
  • Null isn’t handled for close_in; only undefined is checked.

Prefer deriving from the primitive and guard both null/undefined to avoid runtime edge-cases and stale UI.

Apply this diff:

-  const autoCloseStatus = useMemo(() => {
-    if (currentProjectDetails === undefined || currentProjectDetails.close_in === undefined) return false;
-    return currentProjectDetails.close_in !== 0;
-  }, [currentProjectDetails]);
+  const autoCloseStatus = useMemo(() => {
+    const v = currentProjectDetails?.close_in;
+    return v != null && v !== 0;
+  }, [currentProjectDetails?.close_in]);
🧹 Nitpick comments (2)
apps/web/core/components/automation/auto-close-automation.tsx (2)

3-3: useMemo import is fine; optionally simplify by removing memoization

If you adopt the revised dependency fix above, keep useMemo. Alternatively, you can compute the boolean directly without useMemo (MobX observer will re-render when close_in changes), then drop the import.

Optional change if you remove memoization:

-import React, { useMemo, useState } from "react";
+import React, { useState } from "react";

And replace the memo block with:

const v = currentProjectDetails?.close_in;
const autoCloseStatus = v != null && v !== 0;

166-166: Typo in className: stray "ppy" token

The class list includes an invalid "ppy" token which won’t map to any Tailwind class.

Apply this diff:

-                <div className="ppy sm:py-10 flex w-full items-center justify-between gap-2 px-5 py-4">
+                <div className="sm:py-10 flex w-full items-center justify-between gap-2 px-5 py-4">
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d5220e9 and 036e229.

📒 Files selected for processing (2)
  • apps/web/core/components/automation/auto-archive-automation.tsx (4 hunks)
  • apps/web/core/components/automation/auto-close-automation.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/core/components/automation/auto-archive-automation.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/core/components/automation/auto-close-automation.tsx (1)
apps/web/core/store/project/project.store.ts (1)
  • currentProjectDetails (217-220)

@pushya22 pushya22 merged commit 9cf564c into preview Aug 13, 2025
5 of 7 checks passed
@pushya22 pushya22 deleted the fix-automation-page-flicker branch August 13, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛bug Something isn't working ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants