fix(onboarding): Preserve user-entered project slug during platform selection#109609
fix(onboarding): Preserve user-entered project slug during platform selection#109609sentry[bot] wants to merge 1 commit intomasterfrom
Conversation
e8f4af1 to
9a11c80
Compare
9a11c80 to
b0c0b94
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
|
|
||
| const [formData, setFormData] = useState<FormData>(initialData); | ||
| const pickerKeyRef = useRef<'create-project' | 'auto-fill'>('create-project'); | ||
| const hasUserModifiedProjectName = useRef(false); |
There was a problem hiding this comment.
Ref not reset when useEffect clobbers project name
Medium Severity
The hasUserModifiedProjectName ref can desync from actual form state. The existing useEffect (lines 247–251) resets formData.projectName to '' whenever initialData changes (e.g., when defaultTeam updates due to async team loading), but does not reset hasUserModifiedProjectName. After this, the ref is true while the project name is empty, so subsequent platform selection preserves the empty string instead of auto-filling the platform name — a regression from the old behavior which would auto-fill for empty names.
Additional Locations (2)
| const userModifiedName = | ||
| !!formData.projectName && formData.projectName !== formData.platform?.key; | ||
| const newName = userModifiedName ? formData.projectName : value.id; | ||
| const newName = hasUserModifiedProjectName.current ? formData.projectName : value.id; |
There was a problem hiding this comment.
AutoFill project name overwritten on platform change
Low Severity
When autoFill is active (user navigated back from getting-started), the initialData pre-fills projectName from the previously created project (e.g., "my-cool-app"). However, hasUserModifiedProjectName starts as false and is only set true by typing in the input — not by programmatic pre-filling. So if the user changes the platform, handlePlatformChange treats the auto-filled name as auto-generated and overwrites it with the new platform key. The old heuristic (projectName !== platform.key) would have preserved it since the project name typically differs from the platform key.


This PR addresses a bug where a user-entered project slug would be overwritten when a platform was selected during the project creation onboarding flow.
Problem:
Previously, the logic in
handlePlatformChangeattempted to determine if the project name was user-modified by comparingformData.projectNamewithformData.platform?.key. This heuristic was flawed:useEffectthat syncedinitialDatatoformDatacould also inadvertently reset theprojectNamefield ifinitialDatare-evaluated (e.g., due to asynchronous loading of teams), clobbering user input.Solution:
useRef,hasUserModifiedProjectName, to explicitly track whether the user has manually typed into the project slug input field. This provides a reliable signal that the user intends to keep their custom name.onChangehandler for the project name input now setshasUserModifiedProjectName.current = truewhen the user types. It also resets this ref tofalseif the user clears the input, allowing the platform-based auto-fill to take over again.handlePlatformChangenow useshasUserModifiedProjectName.currentto decide whether to overwrite theprojectNamewith the selected platform's ID, ensuring user input is respected.Tests:
Added new test cases to
createProject.spec.tsxto cover:Ref NEW-769