Skip to content

Start the Dock's New RStudio Window with no project - #18786

Merged
gtritchie merged 5 commits into
mainfrom
bugfix/15669-dock-new-window-no-project
Sep 13, 2026
Merged

gtritchie merged 5 commits into
mainfrom
bugfix/15669-dock-new-window-no-project

Conversation

@gtritchie

Copy link
Copy Markdown
Member

On macOS, the Dock icon's "New RStudio Window" command passed the current window's project directory as the new session's working directory. The session then opened the .Rproj file found there, so the new window came up with the same project as the window it was launched from.

The command now asks the session for no project explicitly, and sends no working directory, so the new window starts in the user's Default working directory (Global Options > General > Basic) with no project open. That is where the Qt versions of RStudio started these windows; those versions reopened the project as well, by falling through to "Restore most recently opened project at startup".

Two related changes:

  • launchRStudio() clears RS_INITIAL_PROJECT and RS_INITIAL_WD before setting up the new session's environment. An instance started by opening a project keeps those set for the life of the session -- only a session restart clears them -- so they would otherwise be inherited by the spawned window.
  • The project directory the front end reported to the desktop existed only to give this command a working directory, and is removed.

Verification

Unit tests cover the launch options and the Dock menu item's handler. The Dock menu itself needs a person to click it:

  1. Start RStudio and open a project. Wait 30 seconds, so the project is recorded as the last project.
  2. Right-click the Dock icon and choose "New RStudio Window".
  3. The new window opens with no project, in the Default working directory.

I also confirmed the session behavior directly, with a custom Default working directory and a recorded last project: the session starts with no project and honors the preference.

Addresses #15669

The Dock menu's "New RStudio Window" passed the current project's
directory as the working directory for the new session, and
launchRStudio() then resolved the .Rproj file in that directory and set
RS_INITIAL_PROJECT, so the new window reopened the project already open
in the current window.

Add a noProject option to LaunchRStudioOptions that skips project
resolution, and use it for the Dock command: the new session still
starts in the project directory (#15409) but with no project open.

Addresses #15669
An instance started by opening a project keeps RS_INITIAL_PROJECT set in
its own environment for the life of the session -- only launchNextSession
clears it -- so a session spawned by launchRStudio() inherited it and
opened that project regardless of the requested options.

Addresses #15669
"New RStudio Window" passed the current project's directory as the new
session's working directory, and the project file found there was then
opened, so the new window reopened the project from the window it was
launched from.

Ask the session for no project explicitly instead, and send no working
directory, so the new window starts in the user's default working
directory -- matching what the Qt versions did -- with no project.

Addresses #15669
The desktop tracked the front-end's active project directory solely to
give the Dock's "New RStudio Window" a working directory; that command no
longer sends one, leaving the whole path from Application.java through
the IPC bridge unused.

Addresses #15669
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
2745 0 195 11
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 691 0 38 4
✅ desktop-macos 690 0 42 2
✅ desktop-windows 695 0 41 3
✅ server-linux 639 0 44 2
✅ setup 28 0 20 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit c99ebaceab48f4aceecb9edd76cab17152bd83f5 - Run #950

@gtritchie
gtritchie merged commit 3f38389 into main Sep 13, 2026
34 checks passed
@gtritchie
gtritchie deleted the bugfix/15669-dock-new-window-no-project branch September 13, 2026 16:24

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues. 1 follow-up, 3 nits

🟠 is real but not merge-blocking — either address it here or open an issue to do so later. 🟡 is optional.

  • 🟠 src/node/desktop/src/main/application-launch.ts:84 — the none request also erases the remembered last project, so the original window's project may not be restored on the next launch
  • 🟡 src/node/desktop/src/main/application-launch.ts:78 — launch intent is passed by mutating this process's own env; the trailing "restore" comment no longer restores anything
  • 🟡 src/node/desktop/src/main/application-launch.ts:30 — noProject on the same options bag lets contradictory combinations compile
  • 🟡 src/node/desktop/src/main/application-launch.ts:87 — nested undefined-ternaries and an empty-string sentinel through existsSync

if (options.noProject) {
// ask for no project explicitly, so the session doesn't restore the last one; with no
// working directory of our own the session uses the user's default working directory
setenv(kRStudioInitialProject, kProjectNone);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 With "Restore most recently opened project at startup" on, opening a Dock window erases the remembered project, so the original window's project is not reopened next launch if that window crashes or the new one quits last.

Fix in the session: let the env-var none take the plain no-project path without flushing last-project-path, keeping the flush for the command-line scope.

Why

RS_INITIAL_PROJECT=none lands in SessionProjects.cpp startup at the initialProjectPath() == kProjectNone check, which calls resolveProjectSwitch(kProjectNone). That helper does setLastProjectPath(FilePath()) on the shared per-user record. The original window only rewrites its project into that record on a clean quit (onQuit → saveLastProjectPath), so a crash, OS shutdown, or quitting the empty window last leaves the record empty. Before this PR the Dock window opened the same project, so both windows agreed on it.

Not merge-blocking: nothing is lost on disk, only the one-time automatic reopen. The none env value is only ever sent by this Dock command, so scoping the session change to the env-var half of that condition leaves Workbench's --project none scope and every other startup path untouched.

setenv(kRStudioInitialWorkingDir, workingDir);
// this instance may have been started by opening a project or a file, which leaves these
// variables set in our own environment; clear them so they can't leak to the new session
unsetenv(kRStudioInitialProject);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The child's environment is set up by mutating this process's own process.env around spawn, and the trailing "restore environment variables" comment now restores nothing.

Build an env copy and pass it as the spawn option; both unsetenv pairs and the comment go away.

Why

spawn(process.execPath, argv, { detached: true, stdio: 'ignore', env }) expresses the same intent with no side effect on the parent. The existing "ignores an inherited project" test still holds by asserting on the env passed to the spawn stub.

workingDirectory?: string;

// start the new session with no project, in the user's default working directory
noProject?: boolean;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 noProject next to projectFilePath and workingDirectory lets { noProject: true, projectFilePath } compile and silently drop the path, and launchRStudio({}) now falls through to restore-last-project.

A discriminated union ({ projectFilePath } | { workingDirectory } | { noProject: true }) makes every caller state one intent.

Why

No current caller hits either case; this is about the next caller. Before this PR launchRStudio({}) always set RS_INITIAL_WD to home, which pre-empts the restore-last-project branch in the session; now it sets nothing.

setenv(kRStudioInitialProject, kProjectNone);
} else {
// resolve working directory; callers give us either a directory or a project file
const workingDir =

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Two nested undefined-ternaries plus an empty string threaded through existsSync stand in for what is really two cases.

Branch on which option was given: if (projectFilePath) { ... } else if (workingDirectory) { ... }.

Why

Every caller passes exactly one of the two. resolveProjectFile only returns entries it listed from an existing directory, so the existsSync check is only meaningful for the caller-supplied path; flat cases make that visible and drop the '' sentinel.

@gtritchie

Copy link
Copy Markdown
Member Author

Follow-up for the 🟠 review finding above (the Dock window erasing the remembered last project): #18807 handles the desktop's RS_INITIAL_PROJECT=none in the session without flushing the last project path.

gtritchie added a commit that referenced this pull request Sep 13, 2026
* Keep the last project when the Dock opens a projectless window

The Dock's "New RStudio Window" (#18786) asks the session for no project
by setting RS_INITIAL_PROJECT=none. The session handled that value the
same way as a "--project none" scope: through resolveProjectSwitch(),
which also flushes the per-user last-project path. That record is shared
by every window, so the new empty window erased the project remembered
for the window it was launched from. With "Restore most recently opened
project at startup" on, the original project was then not reopened on
the next launch if that window crashed or the empty window quit last.

Handle the desktop's env-var "none" as a plain projectless start and
leave the last project path alone. The command-line scope keeps its
flush.

Addresses #15669

Claude-Session: https://claude.ai/code/session_01HG3TvVKHo57As36tpZx2T8

* Pass the new session's environment to spawn instead of mutating our own

launchRStudio() set RS_INITIAL_PROJECT and RS_INITIAL_WD in this
process's environment around the spawn call and unset them afterwards,
which also wiped whatever values this instance was started with. Build
the child's environment as a copy and hand it to spawn, leaving our own
untouched.

Make LaunchRStudioOptions a union of the three launch intents (a project
file, a working directory, or no project) so a caller can't combine
them, and branch on the intent directly rather than deriving the working
directory and project file through nested fallbacks.

Claude-Session: https://claude.ai/code/session_01HG3TvVKHo57As36tpZx2T8

This branch was previously deployed

1 inactive deployment
e2e-playwright — c99ebace Deployed Sep 11, 2026 by gtritchie via windows / e2e-desktop-windows (5) #950
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