Repository navigation
Start the Dock's New RStudio Window with no project - #18786
Conversation
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
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
…-window-no-project
gtritchie
left a comment
There was a problem hiding this comment.
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— thenonerequest 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—noProjecton 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 throughexistsSync
| 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); |
There was a problem hiding this comment.
🟠 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); |
There was a problem hiding this comment.
🟡 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; |
There was a problem hiding this comment.
🟡 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 = |
There was a problem hiding this comment.
🟡 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.
|
Follow-up for the 🟠 review finding above (the Dock window erasing the remembered last project): #18807 handles the desktop's |
* 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
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
.Rprojfile 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()clearsRS_INITIAL_PROJECTandRS_INITIAL_WDbefore 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.Verification
Unit tests cover the launch options and the Dock menu item's handler. The Dock menu itself needs a person to click it:
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