Skip to content

Navigating between message threads with browser Back/Forward leaves openingThreadId stale and blocks MessagesPanel #4780

Open

Description

@shafiktanbir

After #4777 (c9521d1), MessagesLayout in both apps/web/app/(ee)/partners.dub.co/(dashboard)/messages/layout.tsx and apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/messages/layout.tsx tracks openingThreadId and loadedThreadId to hide the previous thread until the newly opened thread finishes loading:

useEffect(() => {
  if (!programSlug) {
    setOpeningThreadId(null);
    setLoadedThreadId(null);
  }
}, [programSlug]);

And in PartnerMessagesProgramPage / ProgramMessagesPartnerPageClient:

const showingOpenedThread = !openingThreadId || openingThreadId === programSlug;

However, openingThreadId is only updated when clicking a different item in MessagesList (if (group.id !== activeId) setOpeningThreadId(group.id)) or ProgramSelector / PartnerSelector, and the useEffect in layout.tsx only resets openingThreadId when !programSlug (!partnerId).

As a result:

  1. If you open thread A (/messages/prog-a), click thread B (/messages/prog-b) in MessagesList (which sets openingThreadId = "prog-b" and loadedThreadId = "prog-b"), and then press the browser Back button to return to /messages/prog-a, openingThreadId stays "prog-b" while programSlug is "prog-a". showingOpenedThread evaluates to false, setLoadedThreadId("prog-a") never runs, MessagesPanel receives messages={undefined}, and showThreadSpinner (openingThreadId !== loadedThreadId) stays stuck if loadedThreadId ever differs.
  2. Similarly, if you click thread B in MessagesList (setOpeningThreadId("prog-b")) and then click back on thread A before Next.js finishes changing activeId from "prog-a", group.id !== activeId is false so openingThreadId stays "prog-b" and the spinner overlay stays up indefinitely.

Syncing setOpeningThreadId(programSlug ?? null) (and setOpeningThreadId(partnerId ?? null)) in layout.tsx when the route param changes and setting setOpeningThreadId unconditionally on click in MessagesList / ProgramSelector / PartnerSelector fixes both cases.

Environment:

  • OS: Linux (Ubuntu 24.04)
  • Browser: Brave / Chromium 135
  • Commit: f949c06
Image

Activity

  1. linear commented on Oct 24, 2026

    @linear
  2. shafiktanbir commented on Oct 24, 2026

    @shafiktanbir
    Author

    I pushed a fix for this on my fork here since external PR creation is currently restricted to collaborators:
    main...shafiktanbir:dub:fix/messages-opening-thread-id-sync

    Happy to open the PR if access is enabled, or feel free to cherry-pick fad0405.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions