Skip to content

fix(uikit-playground): update activeScreen/activeProject correctly after deletion#40020

Open
TheSeydiCharyyev wants to merge 3 commits intoRocketChat:developfrom
TheSeydiCharyyev:fix/issue-39240-uikit-playground-active-state
Open

fix(uikit-playground): update activeScreen/activeProject correctly after deletion#40020
TheSeydiCharyyev wants to merge 3 commits intoRocketChat:developfrom
TheSeydiCharyyev:fix/issue-39240-uikit-playground-active-state

Conversation

@TheSeydiCharyyev
Copy link
Copy Markdown

@TheSeydiCharyyev TheSeydiCharyyev commented Apr 1, 2026

Description

Fixes incorrect state management in UIKit Playground when deleting screens and projects.

Related Issue

Closes #39240

Changes Made

DeleteScreen reducer:

  • Fixed crash: Previously, when the last screen was deleted, the reducer deleted the project but then tried to access state.projects[activeProject].flowEdges — causing a crash
    because the project no longer existed
  • Fixed stale reference: Clean up flowEdges and flowNodes before potentially deleting the project
  • Added fallback: When all screens are deleted and the project is removed, activeProject and activeScreen now fall back to the first remaining project instead of leaving stale
    references

DeleteProject reducer:

  • Added fallback: Previously always set activeProject: '' even when other projects existed. Now falls back to the first remaining project
  • Replaced .map() with .forEach() for the delete side effect (lint best practice)
  • Removed console.log from production code

Manual Testing

  1. Open UIKit Playground
  2. Create two projects with multiple screens
  3. Delete the active screen — active screen should switch to the next remaining screen
  4. Delete all screens in a project — project should be removed, active project should switch to the remaining one
  5. Delete a project directly — active project should switch to the remaining one
  6. Delete all projects — activeProject and activeScreen should be empty strings

Summary by CodeRabbit

  • Bug Fixes

    • Deleting a screen now removes associated flow connections and selects the nearest remaining screen; if no screens remain, a new untitled project and screen are created and selected.
    • Deleting a project preserves the current selection when removing a non-active project; if the active project is removed, the next project/screen is auto-selected or a new untitled project/screen is created.
  • Chores

    • Removed stray debug logging.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Apr 1, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

⚠️ No Changeset found

Latest commit: 9877ea7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 892ecf46-8d08-452c-bd24-193ddf6fa71e

📥 Commits

Reviewing files that changed from the base of the PR and between fd8c45c and 9877ea7.

📒 Files selected for processing (1)
  • apps/uikit-playground/src/Context/reducer.ts
📜 Recent review details
⏰ 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). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/uikit-playground/src/Context/reducer.ts
🧠 Learnings (3)
📚 Learning: 2026-03-04T14:16:49.202Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39304
File: packages/ui-contexts/src/ActionManagerContext.ts:26-26
Timestamp: 2026-03-04T14:16:49.202Z
Learning: In `packages/ui-contexts/src/ActionManagerContext.ts` (TypeScript, RocketChat/Rocket.Chat), the `disposeView` method in `IActionManager` uses an intentionally explicit union `UiKit.ModalView['id'] | UiKit.BannerView['viewId'] | UiKit.ContextualBarView['id']` to document which view types are accepted, even though all constituents resolve to the same primitive. The inline `// eslint-disable-next-line typescript-eslint/no-duplicate-type-constituents` comment is intentional and should not be flagged or removed.

Applied to files:

  • apps/uikit-playground/src/Context/reducer.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/uikit-playground/src/Context/reducer.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/uikit-playground/src/Context/reducer.ts
🔇 Additional comments (2)
apps/uikit-playground/src/Context/reducer.ts (2)

196-242: DeleteScreen logic correctly handles adjacent screen selection and empty project fallback.

The implementation properly:

  • Computes deletedScreenIndex before deletion
  • Updates activeScreen only when the deleted screen was active
  • Uses Math.min(deletedScreenIndex, project.screens.length - 1) to select the nearest remaining screen
  • Cleans up flowEdges and flowNodes before potentially deleting the project
  • Creates a default project/screen when all projects are removed

One minor defensive consideration: Line 217 assumes state.projects[nextProjectId].screens[0] exists. While the app logic ensures projects always have at least one screen, a guard could prevent edge-case crashes if state becomes inconsistent.


313-360: DeleteProject logic correctly gates state updates and handles fallback creation.

The implementation properly:

  • Uses .forEach() instead of .map() for delete side effects (appropriate since return value was unused)
  • Returns early when the deleted project isn't the active one, preserving current selection
  • Falls back to the first remaining project or creates a new default project/screen
  • Removes the debug console.log from production code

The fallback project/screen structure correctly matches the initialState pattern with all required fields (flowEdges, flowNodes, actionPreview).


Walkthrough

Adjusts reducer deletion logic in the UIKit Playground: deleting a screen now removes it from its project and related flow edges/nodes before recalculating activeScreen or deleting the empty project; deleting a project now skips updating active state when the removed project wasn't active and removes a debug log.

Changes

Cohort / File(s) Summary
Deletion Logic
apps/uikit-playground/src/Context/reducer.ts
Reworked DeleteScreen to remove the screen object, update the active project's screens, flowEdges, and flowNodes, then recalculate activeScreen or delete the project if it becomes empty. Updated DeleteProject to remove a console.log, use forEach for screen deletions, delete the project entry, and only change activeProject/activeScreen when the deleted project was the active one.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: fixing incorrect activeScreen/activeProject updates after deletion operations.
Linked Issues check ✅ Passed The PR implementation addresses all primary objectives from #39240: updating activeScreen/activeProject after deletion, removing empty projects, selecting nearest remaining screen, and maintaining UI consistency.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing deletion state management. Modifications include DeleteScreen cleanup logic, DeleteProject fallback handling, removing debug logging, and using forEach for side effects—all aligned with PR objectives.
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.


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
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/uikit-playground/src/Context/reducer.ts">

<violation number="1" location="apps/uikit-playground/src/Context/reducer.ts:302">
P2: Deleting a non-active project incorrectly forces `activeProject` to the first remaining project, overriding the current active selection.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/uikit-playground/src/Context/reducer.ts`:
- Around line 197-206: The reducer always sets state.activeScreen =
project.screens[0] after deletion which changes selection incorrectly; instead,
compute the new screens array (project.screens filtered) and if the deleted id
(action.payload) was not the current state.activeScreen leave state.activeScreen
untouched, but if it was the active one choose the screen at the same index in
the filtered array (i.e., keep the slot: use the index of the deleted item in
the original project.screens to pick the element at that index in the filtered
project.screens if present, otherwise pick the previous element) — update the
logic around state.projects[activeProject], project.screens, and
state.activeScreen to implement this selection-preserving behavior.
- Around line 297-303: The reducer currently resets activeProject
unconditionally after any deletion; change it so the reset only happens when the
deleted project is the currently active one by checking if action.payload ===
state.activeProject before assigning activeProject and activeScreen; update the
block around activeProject/activeScreen (in the reducer handling project
deletions) to gate the assignment with that conditional and keep the existing
state otherwise (and still handle the case where there are no remaining
projects).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0ada45a2-eac8-44b6-84b3-4a667cfb7778

📥 Commits

Reviewing files that changed from the base of the PR and between 02b35d5 and 672cd90.

📒 Files selected for processing (1)
  • apps/uikit-playground/src/Context/reducer.ts
📜 Review details
⏰ 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). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/uikit-playground/src/Context/reducer.ts
🧠 Learnings (2)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/uikit-playground/src/Context/reducer.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/uikit-playground/src/Context/reducer.ts

@coderabbitai coderabbitai bot removed the type: bug label Apr 1, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 1, 2026

CLA assistant check
All committers have signed the CLA.

…agement

- DeleteScreen: only update activeScreen when the deleted screen was
  the active one, and select the nearest screen by index instead of
  always picking the first
- DeleteScreen/DeleteProject: create a default project+screen instead
  of setting activeProject/activeScreen to empty strings, preventing
  crashes in useNodesAndEdges, PrototypeContainer, and SurfaceSelect
- Remove unnecessary `|| ''` fallbacks now that empty state is handled

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(uikit-playground): activeScreen and activeProject not updated correctly after deletion

2 participants