Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat: split out components from ChatView.tsx #860

MergedYmit24(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/860/headmerged by juliusmarminge View on GitHub

What Changed

Split out all of the components from ChatView.tsx into their own files, and pulled the functions into a ChatView.logic.ts. I didn't change the actual content of those components, just moved them to their own files.

Why

In order to tame the massive ChatView.tsx file (and ChatView component!) it is basically required that we move out some of this functionality, otherwise any attempts to refactor will be met with merge conflict hell. It's fair that some of these components I broke out might belong together, however, it is much easier to break them all out and later put them back together in smaller PRs. This way we can independently work to refactor individual aspects (e.g. message timeline component).

I considered making this multiple PRs due to volume of code changes, however i choose not two because:

  1. AI makes it easier to validate that content didn't change, just organization.
  2. I didn't want to spam 10 PRs just to get a number lower arbitrarily.

This is associated with the effort of #830, i don't mean to step on toes if others are working on this effort, hopefully this split will make it much easier for many to work on individual parts of this refactor in a more coordinated matter!

UI Changes

No UI changes, pure refactor.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

(technically this is not a small PR, but it is very very focused.)

Future Work

Rather than having a single super ChatView component, we should lower some of the responsibilities to more appropriate locations in the component tree. Ideally, in my opinion, ChatView itself should be quite small and only handle orchestrating the various major components it mounts (e.g. the header, timeline, composer, etc...).

Note

Split ChatView.tsx into modular chat sub-components

Extracts a large number of components and utilities previously inlined in ChatView.tsx into separate files under apps/web/src/components/chat/.

  • New components include MessagesTimeline, ChatHeader, ProposedPlanCard, ProviderModelPicker, ProviderHealthBanner, ThreadErrorBanner, ComposerCommandMenu, ComposerPendingUserInputPanel, ComposerPendingApprovalPanel, ChangedFilesTree, OpenInPicker, and several smaller UI pieces.
  • Logic helpers (blob URL management, draft thread construction, model resolution, localStorage utilities) are extracted into ChatView.logic.ts.
  • ChatView.tsx is refactored to import from these new modules, with no intended change to runtime behavior.
📊 Macroscope summarized 24b93b3. 20 files reviewed, 4 issues evaluated, 2 issues filtered, 1 comment posted

🗂️ Filtered Issues

apps/web/src/components/chat/MessageCopyButton.tsx — 1 comment posted, 2 evaluated, 1 filtered
  • line 11: The setTimeout at line 11 is not cleaned up when the component unmounts. If the user navigates away or the message is removed before 2 seconds elapse, React will warn about setting state on an unmounted component. The equivalent code in ChatMarkdown.tsx stores the timer ref and clears it in a useEffect cleanup. [ Failed validation ]
apps/web/src/components/chat/ProviderModelPicker.tsx — 0 comments posted, 1 evaluated, 1 filtered
  • line 28: The type guard isAvailableProviderOption asserts the return type narrows value to ProviderKind, but the runtime check only excludes "claudeCode" via option.value !== "claudeCode". Looking at ProviderPickerKind = ProviderKind | "claudeCode" | "cursor", the guard should also exclude "cursor" to properly narrow to ProviderKind. If cursor ever becomes available (available: true), the function would return true but the type annotation would incorrectly claim option.value is ProviderKind when it's actually "cursor", causing type unsoundness. [ Out of scope (triage) ]
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: e3cb2de5-f507-45b1-a7db-3ccdd94c3458

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Post copyable unit tests in a comment

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. I'm not opposed to this change, I am opposed to how the files are structured. Potentially we could put them in a folder or something?

    4. Ymit24(GitHub profile, opens in a new tab)commented

      Thoughts on “/chat” in the components folder for the organization? @binbandit

    5. Thoughts on “/chat” in the components folder for the organization? @binbandit

      Ye. That works nicely. It explains it well 😂

    6. Very cool, I’ll push a new commit with the change, thanks for the feedback!

    7. updated to move the files into /chat. Also rebased to get new changes from https://github.com/pingdotgg/t3code/pull/488 in ChatView.tsx

    8. how much of ChatView is now invoking hooks and just passing down to child components? Can we have the child components own their state more? e.g. composer can probably just fetch the state from store directly, instead of the chatview pulling it just to pass it down as props?

    9. Most of ChatView right now is as you describe, @juliusmarminge. Unfortunately, a lot of the useEffects and various callbacks are fairly intertwined 😅. I'm working on pulling out the composer pieces right now and already reduced ChatView significantly, so seems very promising. I think a couple of focused stacked PRs will be able to split it apart nicely. The tough part is balancing splitting it up and actually improving the architecture without accidentally introducing subtle bugs.

    10. nmggithub(GitHub profile, opens in a new tab)commented

      Excited to see work on this. Out of curiosity, how much does this refactor out Plan mode? I see some components split out (as was the original ask), but I feel like the business logic of Plan mode should be kept logically separate as well. Not sure if that's scope creep, though.

    11. This first pass is just moving stuff. I’m working on a second pass to actually lower hooks down out of chatview into respective subcomponents. I haven’t explicitly touched moving out plan mode but i imagine that would naturally happen as this line of work progresses.

    12. @juliusmarminge , just curious, does this PR block any ChatView.tsx-related work in other PR's? I would suspect there would be a lot of merge conflicts to deal with if it didn't. But perhaps we could make it work.

    13. @juliusmarminge , just curious, does this PR block any ChatView.tsx-related work in other PR's? I would suspect there would be a lot of merge conflicts to deal with if it didn't. But perhaps we could make it work.

      it's always gonna conflict. will pull and test it now and merge so others can rebase their stuff

    14. @macroscope-app review this

    15. @@ -0,0 +1,10 @@
      1+import { memo, useCallback, useState } from "react";
      2+import { CopyIcon, CheckIcon } from "lucide-react";
      3+import { Button } from "../ui/button";
      4+
      5+export const MessageCopyButton = memo(function MessageCopyButton({ text }: { text: string }) {
      6+ const [copied, setCopied] = useState(false);
      7+
      8+ const handleCopy = useCallback(() => {
      9+ void navigator.clipboard.writeText(text);
      10+ setCopied(true);

      🟢 Low chat/MessageCopyButton.tsx:8

      navigator.clipboard is undefined in non-secure contexts (HTTP), so navigator.clipboard.writeText(text) throws TypeError: Cannot read property 'writeText' of undefined. Consider adding a null check before calling writeText, similar to the guard in ChatMarkdown.tsx.

      -  const handleCopy = useCallback(() => {
      -    void navigator.clipboard.writeText(text);
      +  const handleCopy = useCallback(() => {
      +    if (typeof navigator === "undefined" || navigator.clipboard == null) {
      +      return;
      +    }
      +    void navigator.clipboard.writeText(text);
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file apps/web/src/components/chat/MessageCopyButton.tsx around lines 8-10:
      
      `navigator.clipboard` is `undefined` in non-secure contexts (HTTP), so `navigator.clipboard.writeText(text)` throws `TypeError: Cannot read property 'writeText' of undefined`. Consider adding a null check before calling `writeText`, similar to the guard in `ChatMarkdown.tsx`.
      
      Evidence trail:
      - `apps/web/src/components/chat/MessageCopyButton.tsx` line 9: `void navigator.clipboard.writeText(text);` (no null check)
      - `apps/web/src/components/ChatMarkdown.tsx` lines 140-142: shows the null guard pattern `if (typeof navigator === "undefined" || navigator.clipboard == null) { return; }`
      - `apps/web/src/components/Sidebar.tsx` lines 92-95: another guard example `if (typeof navigator === "undefined" || navigator.clipboard?.writeText === undefined)`
      - Microsoft documentation confirms Clipboard API is secure-context only: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/working-with-local-content
    16. lgtm as a first pass. feel free to do follow ups breaking out the logic into relevant components too :)

    17. juliusmarminge merged thise3d46b6

    18. juliusmarminge closed this

Sign in to join this conversation.