Skip to content

fix(web): New Session button on fresh start / no-opened-projects#37591

Closed
ndj888 wants to merge 1 commit into
anomalyco:devfrom
ndj888:fix/web-new-session-empty-projects
Closed

fix(web): New Session button on fresh start / no-opened-projects#37591
ndj888 wants to merge 1 commit into
anomalyco:devfrom
ndj888:fix/web-new-session-empty-projects

Conversation

@ndj888

@ndj888 ndj888 commented Jul 18, 2026

Copy link
Copy Markdown

Problem

When you run opencode web for the first time (or with no persisted project state), the Web UI becomes unusable because:

  1. Titlebar "New Session" button (+): Clicking does nothing — the handler (openNewTab) falls through 5 cases and silently returns when none find a project directory.

  2. Home page "New Session" buttons: Hidden entirely because newSessionProject() returns undefined when projects() (persisted opened-projects list) is empty.

The issue persists even though the server does have registered projects (returned by GET /project).

Root Cause

The web UI stores opened projects in localStorage (opencode.global.dat:serverprojects.<scope>). On fresh start:

  • global.servers.list() may be populated (via entry.tsx servers={[server]}), but
  • global.ensureServerCtx(conn).projects.list() reads only persisted projects — which are empty on first launch.

The server-registered projects (from sync.data.project, populated by the /project API) are never consulted as a fallback for session creation.

Reproduce

opencode web --port 4096
# Open http://127.0.0.1:4096/
# Click "New Session"  →  nothing happens

Fix

Two targeted changes:

  1. packages/app/src/pages/home.tsxnewSessionProject():

    • Add a final ?? focusedSync().data.project[0] fallback.
    • When no project is opened, picks the first server-registered project so the empty-state and in-list "New Session" buttons appear and work.
  2. packages/app/src/components/titlebar.tsxopenNewTab():

    • After the 5-case fallback chain fails, add a Case 6 that reads global.ensureServerCtx(conn).sync.data.project[0].
    • Uses the server-registered projects as the last-resort directory for creating a new draft session.

Verification

Manually tested on opencode web --port 19820 with cleared localStorage:

  • Page loads with server-registered project visible as the source for new sessions
  • Titlebar "New Session" button navigates to /new-session?draftId=...
  • Home page show "New Session" buttons in both the empty state and session list
  • All API requests return HTTP 200

…ects

On a fresh `opencode web` start, the "New Session" button in the titlebar
silently does nothing and the home page hides its "New Session" buttons.
This happens because:

1. `newSessionProject()` in home.tsx relies solely on
   `projects()` (persisted opened projects), which is empty.

2. `openNewTab()` in titlebar.tsx has a 5-case fallback chain that
   all fail when no projects are persisted: home selection is empty,
   layout.projects.list() is empty, and
   global.ensureServerCtx(conn).projects.list() returns only persisted
   projects — never server-registered ones.

Fix:
- home.tsx: add sync data fallback to `newSessionProject` (registered
  projects from the server API)
- titlebar.tsx: add a final fallback that reads server-registered
  projects from sync.data.project when all other cases fail
@ndj888
ndj888 requested review from Brendonovich and Hona as code owners July 18, 2026 02:02
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Jul 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 18, 2026
@github-actions github-actions Bot closed this Jul 18, 2026
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.

1 participant