Skip to content

fix: preserve custom chat widget URL and icon on deselect (NES-1522)#8940

Open
jianwei1 wants to merge 2 commits intomainfrom
jianweichong/nes-1522-custom-chat-widget-clears-url-and-icon-selection-when
Open

fix: preserve custom chat widget URL and icon on deselect (NES-1522)#8940
jianwei1 wants to merge 2 commits intomainfrom
jianweichong/nes-1522-custom-chat-widget-clears-url-and-icon-selection-when

Conversation

@jianwei1
Copy link
Copy Markdown
Contributor

@jianwei1 jianwei1 commented Mar 31, 2026

Summary

  • Bug: Custom chat widget loses URL and icon selection when unchecked and re-checked — dedicated platforms (Facebook, WhatsApp, Telegram) preserve their data but custom widgets do not
  • Root cause: Dynamic React key prop on custom ChatOption components changes when the button is deleted, causing React to unmount/remount and destroy local useState state
  • Fix: Use stable keys ("custom-0", "custom-1") to preserve the component instance, plus a render-time state reset to handle the shift case (2 custom buttons where the first is deleted)

Changes

File Change
Chat.tsx Changed dynamic keys to static keys on custom ChatOption slots
ChatOption.tsx Added trackedId state + render-time sync guard to handle button identity changes
ChatOption.spec.tsx Added 2 tests: state sync on button change + state preservation on deselect

Test plan

  • All 15 existing + new tests pass (Chat.spec.tsx + ChatOption.spec.tsx)
  • Scenario A: Select custom widget → set icon + URL → uncheck → re-check → URL and icon preserved
  • Scenario B: Select 2 custom widgets with different URLs/icons → uncheck first → second shifts correctly
  • Scenario C: Select 2 custom widgets → uncheck second → first unchanged
  • Scenario D: Deselect → re-select → refresh page → data persisted on server
  • Scenario E: Toggle dedicated platforms (Facebook/WhatsApp/Telegram) off and on → regression check

Post-Deploy Monitoring & Validation

No additional operational monitoring required: UI-only change scoped to the Chat Widget editor panel. No backend, API, or data model changes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where custom chat options could lose their configured URL and icon when deselected and then reselected by stabilizing component identity and preserving local state.
  • Tests

    • Added tests covering chat option state synchronization on reconfiguration and state preservation when options are deselected.
  • Documentation

    • Added a plan describing the fix, verification scenarios, and test coverage.

Use stable React keys on custom ChatOption slots to prevent
unmount/remount when the backing button is deleted. Add render-time
state reset to sync local state when a different button shifts into
the same slot.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@jianwei1 jianwei1 self-assigned this Mar 31, 2026
@jianwei1 jianwei1 requested a review from csiyang March 31, 2026 22:32
@linear
Copy link
Copy Markdown

linear bot commented Mar 31, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 17a9e4f1-6602-49b3-9602-3261e0fe5dd6

📥 Commits

Reviewing files that changed from the base of the PR and between ddec1d4 and f99ca7b.

📒 Files selected for processing (2)
  • apps/journeys-admin/src/components/Editor/Slider/Settings/CanvasDetails/JourneyAppearance/Chat/ChatOption/ChatOption.spec.tsx
  • docs/plans/2026-03-31-001-fix-custom-chat-widget-clears-url-icon-on-deselect-plan.md
✅ Files skipped from review due to trivial changes (2)
  • apps/journeys-admin/src/components/Editor/Slider/Settings/CanvasDetails/JourneyAppearance/Chat/ChatOption/ChatOption.spec.tsx
  • docs/plans/2026-03-31-001-fix-custom-chat-widget-clears-url-icon-on-deselect-plan.md

Walkthrough

Stabilizes React reconciliation for two custom chat slots by using static keys and adds per-instance identity tracking in ChatOption to sync state from a new chatButton ID while preserving local state when chatButton becomes undefined. Tests and a plan document were added.

Changes

Cohort / File(s) Summary
React Key Stabilization
apps/journeys-admin/src/components/Editor/Slider/Settings/CanvasDetails/JourneyAppearance/Chat/Chat.tsx
Replaced dynamic keys derived from customButtons[n]?.id with static keys ("custom-0", "custom-1") for custom ChatOption slots to preserve component identity when underlying data is temporarily undefined.
State Synchronization Logic
apps/journeys-admin/src/components/Editor/Slider/Settings/CanvasDetails/JourneyAppearance/Chat/ChatOption/ChatOption.tsx
Added trackedId local state and logic to update currentLink and currentPlatform when chatButton?.id changes to a new ID; explicitly avoids resetting state when chatButton becomes undefined to retain user-entered values.
Test Coverage
apps/journeys-admin/src/components/Editor/Slider/Settings/CanvasDetails/JourneyAppearance/Chat/ChatOption/ChatOption.spec.tsx
Added tests verifying: (1) prop-driven state updates when chatButton changes identity, and (2) state preservation when chatButton is set to undefined after being active.
Documentation / Plan
docs/plans/2026-03-31-001-fix-custom-chat-widget-clears-url-icon-on-deselect-plan.md
New plan describing the behavior changes, verification scenarios, and rationale for static keys and identity-based state sync.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 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 and concisely summarizes the main bug fix—preserving custom chat widget URL and icon on deselect—which aligns with the PR's primary objective and all code changes.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jianweichong/nes-1522-custom-chat-widget-clears-url-and-icon-selection-when

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.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 31, 2026

View your CI Pipeline Execution ↗ for commit f99ca7b

Command Status Duration Result
nx run journeys-admin-e2e:e2e ✅ Succeeded 29s View ↗
nx run-many --target=vercel-alias --projects=jo... ✅ Succeeded 2s View ↗
nx run-many --target=upload-sourcemaps --projec... ✅ Succeeded 9s View ↗
nx run-many --target=deploy --projects=journeys... ✅ Succeeded 3m 15s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-31 22:46:43 UTC

@github-actions github-actions bot requested a deployment to Preview - journeys-admin March 31, 2026 22:33 Pending
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin March 31, 2026 22:38 Inactive
@github-actions
Copy link
Copy Markdown
Contributor

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys-admin ✅ Ready journeys-admin preview Wed Apr 1 11:43:25 NZDT 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

Development

Successfully merging this pull request may close these issues.

1 participant