🎯 fix: Preserve Selected Artifact When Clicking Artifact Button - #12601
Conversation
|
Hey @starchow, thanks for digging into this one — the diagnosis is right and dropping the 1. Toggle-close regression in
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9db368cce9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Hi @danny-avila I've changed the code as your feedbacks, please review it again. Thanks. |
- Remove `userHasManualSelection` guard from effect LibreChat-AI#3: it cannot distinguish manual clicks from system auto-selection, blocking auto-advancement to new artifacts during streaming. - Add JSDoc on `currentArtifactIdRef` explaining why it must not be added to effect deps (toggle-close regression). - Add test verifying auto-advancement during streaming.
…eChat-AI#12601) * fix: preserve selected artifact when clicking artifact button * fix: preserve artifact selection on click and during streaming * fix: remove broken streaming guard, add JSDoc and test - Remove `userHasManualSelection` guard from effect LibreChat-AI#3: it cannot distinguish manual clicks from system auto-selection, blocking auto-advancement to new artifacts during streaming. - Add JSDoc on `currentArtifactIdRef` explaining why it must not be added to effect deps (toggle-close regression). - Add test verifying auto-advancement during streaming. * style: use standard multi-line JSDoc format for ref comment --------- Co-authored-by: Danny Avila <danny@librechat.ai>
Resolves conflicts from: - Sidebar Icon Toggle (LibreChat-AI#12642) - kept our branding logo, took upstream's setActive prop change on NewChatButton - Command Popover UX (LibreChat-AI#12677) - adopted upstream's popoverAtom pattern in ChatForm/Mention, kept Jotai in useHandleKeyUp - Preserve Selected Artifact (LibreChat-AI#12601) - accepted upstream's fix - Entra ID Group Sync (LibreChat-AI#12606) - accepted upstream's expanded logic - families.ts - kept our Jotai atomFamily definitions, added effectiveEndpointByIndex as Jotai selector Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…eChat-AI#12601) * fix: preserve selected artifact when clicking artifact button * fix: preserve artifact selection on click and during streaming * fix: remove broken streaming guard, add JSDoc and test - Remove `userHasManualSelection` guard from effect LibreChat-AI#3: it cannot distinguish manual clicks from system auto-selection, blocking auto-advancement to new artifacts during streaming. - Add JSDoc on `currentArtifactIdRef` explaining why it must not be added to effect deps (toggle-close regression). - Add test verifying auto-advancement during streaming. * style: use standard multi-line JSDoc format for ref comment --------- Co-authored-by: Danny Avila <danny@librechat.ai>
…eChat-AI#12601) * fix: preserve selected artifact when clicking artifact button * fix: preserve artifact selection on click and during streaming * fix: remove broken streaming guard, add JSDoc and test - Remove `userHasManualSelection` guard from effect LibreChat-AI#3: it cannot distinguish manual clicks from system auto-selection, blocking auto-advancement to new artifacts during streaming. - Add JSDoc on `currentArtifactIdRef` explaining why it must not be added to effect deps (toggle-close regression). - Add test verifying auto-advancement during streaming. * style: use standard multi-line JSDoc format for ref comment --------- Co-authored-by: Danny Avila <danny@librechat.ai>
Summary
Clicking an artifact button in the conversation incorrectly resets the view to the latest artifact instead of opening the clicked one. This happens because:
ArtifactButtonwas callingresetCurrentArtifactId()and then relying on asetTimeoutto set the correct ID 15ms later — a race condition with theuseArtifactseffect.useArtifactseffect unconditionally overwritescurrentArtifactIdwith the latest artifact wheneverorderedArtifactIdschanges, clobbering the user's selection.This PR fixes both issues:
ArtifactButtonnow sets the artifact ID directly viasetCurrentArtifactId(artifact.id)instead of the reset +setTimeoutworkaround.currentArtifactIdRefto read the current selection without subscribing as a reactive dependency. This preserves valid user selections when new artifacts are added, while still falling back to the latest artifact when no valid selection exists. The ref pattern avoids a toggle-close regression that occurs whencurrentArtifactIdis added directly to the effect's dependency array.userHasManualSelectionguard was explored but reverted because it cannot distinguish manual clicks from system auto-selection, which blocked auto-advancement to new artifacts during streaming.Three new tests cover the behavioral contracts: selection preservation on new artifact, auto-advancement during streaming, and reset stability (no bounce-back after toggle-close).
Change Type
Testing
Checklist