Skip to content

fix: update slug as workspace name is entered#4151

Merged
perkinsjr merged 12 commits intomainfrom
eng-2076-enhancement-improve-onboarding-form-slug-generation
Nov 4, 2025
Merged

fix: update slug as workspace name is entered#4151
perkinsjr merged 12 commits intomainfrom
eng-2076-enhancement-improve-onboarding-form-slug-generation

Conversation

@MichaelUnkey
Copy link
Collaborator

What does this PR do?

Fixes # (issue)
ENG-2076

If there is not an issue for this, please create one first. This is used to tracking purposes and also helps use understand why this PR exists

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Workspace creation still functions as intended
  • Slug should auto generate as workspace name is entered
  • If slug is edited it should re validate form

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

@linear
Copy link

linear bot commented Oct 23, 2025

@changeset-bot
Copy link

changeset-bot bot commented Oct 23, 2025

⚠️ No Changeset found

Latest commit: dbecc76

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
engineering Ready Ready Preview Comment Nov 4, 2025 2:17pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
dashboard Ignored Ignored Preview Nov 4, 2025 2:17pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

📝 Walkthrough

Walkthrough

Reworked workspace creation hook: added hydration-safe rendering (isMounted), default form values, onChange-driven slug auto-generation and normalization, live-validFieldCount using form.watch, and explicit slugManuallyEdited tracking; removed blur-based slug generation and adjusted placeholder/hydration behavior.

Changes

Cohort / File(s) Summary
Workspace form hook
apps/dashboard/app/new/hooks/use-workspace-step.tsx
Added useEffect/isMounted to avoid hydration flicker, introduced defaultValues for workspaceName and slug, moved slug auto-generation from onBlur to onChange (workspaceName triggers conditional slugify when not manually edited), enhanced slug onChange to normalize via slugify, clear slug errors, set slugManuallyEdited, and retrigger validation; updated validFieldCount to use live form.watch values and adjusted slug placeholder rendering based on isMounted.

Sequence Diagram(s)

sequenceDiagram
    participant UI as User Input
    participant Hook as useWorkspaceStep Hook
    participant Validator as Validation Logic
    note over Hook,Validator #DDEBF7: Hydration-safe, onChange-driven generation
    UI->>Hook: mount -> Hook sets isMounted = true
    UI->>Hook: change workspaceName
    Hook->>Validator: validate workspaceName
    alt workspaceName.length >= 3 AND NOT slugManuallyEdited
        Hook->>Hook: generate slug = slugify(workspaceName)
        Hook->>Validator: validate slug
    else
        Hook->>Hook: do not auto-generate slug
    end
Loading
sequenceDiagram
    participant UI as User Input
    participant Hook as useWorkspaceStep Hook
    participant Validator as Validation Logic
    note over Hook,Validator #F7F3DD: Slug normalization & manual-edit tracking
    UI->>Hook: change slug (user types)
    Hook->>Hook: clear slug errors
    Hook->>Hook: slug = slugify(input)
    Hook->>Hook: set slugManuallyEdited = input.length > 0
    Hook->>Validator: validate slug
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect isMounted usage and placeholder/hydration behavior.
  • Verify defaultValues interactions with form library and initial validation.
  • Check slugManuallyEdited edge cases and when errors are cleared.
  • Confirm validFieldCount now reflects form.watch accurately.

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "fix: update slug as workspace name is entered" directly reflects the main change described in the raw summary, which involves replacing onBlur-based slug auto-generation with onChange-driven hydration so the slug updates as the workspace name is entered. The title is concise, clear, and specific enough for a teammate to understand the primary change without being vague or off-topic. It accurately summarizes the core functionality improvement without unnecessary noise or file references.
Description Check ✅ Passed The PR description follows the required template structure and includes all major sections: "What does this PR do?" with an issue reference (ENG-2076), "Type of change" with bug fix selected, "How should this be tested?" with three practical test cases, and a complete "Checklist" section showing the author completed all required checks. While the issue reference format is slightly unconventional (appearing as a template placeholder followed by the ID rather than as a single formatted reference), the essential information is present and the description provides sufficient context for reviewers to understand the change, how to verify it, and that the author has completed their pre-merge responsibilities.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch eng-2076-enhancement-improve-onboarding-form-slug-generation

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a0f9be and 8579414.

📒 Files selected for processing (1)
  • apps/dashboard/app/new/hooks/use-workspace-step.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/app/new/hooks/use-workspace-step.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Build / Build
  • GitHub Check: Test API / API Test Local
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/dashboard/app/new/hooks/use-workspace-step.tsx (1)

157-185: Critical: onChange prop overrides registered onChange handler.

The slug field has two onChange handlers: one registered via form.register("slug", { onChange: ... }) at lines 157-168, and a separate onChange prop at lines 175-185. React Hook Form spreads the registered props first, then the separate onChange prop overrides the registered handler, causing the logic at lines 159-167 to never execute.

Additionally, this creates code duplication:

  • Error clearing: lines 159-161 and 176-178
  • Flag setting: lines 163 and 180
  • Validation trigger: lines 166 and 184

Remove the registered onChange and keep only the prop onChange, eliminating the override conflict and duplication:

-            <FormInput
-              {...form.register("slug", {
-                onChange: (evt) => {
-                  // If we don't clear the manually set error, it will persist even if the user clears
-                  // or changes the input
-                  form.clearErrors("slug");
-                  const v = evt.currentTarget.value;
-                  setSlugManuallyEdited(v.length > 0);
-
-                  // Re-validate on change to update validFieldCount
-                  form.trigger("slug");
-                },
-              })}
+            <FormInput
+              {...form.register("slug")}
               placeholder="enter-a-handle"
               label="Workspace URL handle"
               required
🧹 Nitpick comments (1)
apps/dashboard/app/new/hooks/use-workspace-step.tsx (1)

181-184: Remove redundant validation trigger.

Line 181 calls form.setValue("slug", slugify(v), { shouldValidate: true }), which already triggers validation for the slug field. The subsequent form.trigger("slug") at line 184 is redundant and causes double validation on every keystroke.

Apply this diff to remove the redundant trigger:

                 form.setValue("slug", slugify(v), {
                   shouldValidate: true,
                 });
-                form.trigger("slug");
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f07bd3 and 3d0aa55.

📒 Files selected for processing (1)
  • apps/dashboard/app/new/hooks/use-workspace-step.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-04T17:27:09.821Z
Learnt from: chronark
PR: unkeyed/unkey#2146
File: apps/dashboard/app/(app)/apis/[apiId]/settings/default-prefix.tsx:74-75
Timestamp: 2024-10-04T17:27:09.821Z
Learning: In `apps/dashboard/app/(app)/apis/[apiId]/settings/default-prefix.tsx`, the hidden `<input>` elements for `workspaceId` and `keyAuthId` work correctly without being registered with React Hook Form.

Applied to files:

  • apps/dashboard/app/new/hooks/use-workspace-step.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build / Build
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Test Go API Local / Test

Copy link
Contributor

@ogzhanolguncu ogzhanolguncu left a comment

Choose a reason for hiding this comment

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

Screen.Recording.2025-10-24.at.16.15.16.mov

I think we have a problem clearing it

@vercel vercel bot temporarily deployed to Preview – dashboard October 24, 2025 19:42 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard October 27, 2025 17:21 Inactive
@vercel vercel bot temporarily deployed to Preview – engineering October 27, 2025 20:14 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard October 27, 2025 20:16 Inactive
Copy link
Collaborator

@chronark chronark left a comment

Choose a reason for hiding this comment

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

there is some flickering as the slug input loads, otherwise it works well

Screen Recording 2025-10-28 at 06.23.47.mov (uploaded via Graphite)

@vercel vercel bot temporarily deployed to Preview – engineering October 29, 2025 16:45 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard October 29, 2025 16:47 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard October 29, 2025 18:47 Inactive
Copy link
Contributor

@ogzhanolguncu ogzhanolguncu left a comment

Choose a reason for hiding this comment

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

LGTM. I didn't see any flicker or any other weirdness 😄

@graphite-app
Copy link

graphite-app bot commented Nov 4, 2025

Movie gif. Actor Chow Yun-fat leans out of a doorway casually chewing while giving a cool, confident thumbs-up of approval. (Added via Giphy)

@perkinsjr perkinsjr enabled auto-merge November 4, 2025 14:16
@perkinsjr perkinsjr added this pull request to the merge queue Nov 4, 2025
@vercel vercel bot temporarily deployed to Preview – engineering November 4, 2025 14:17 Inactive
Merged via the queue into main with commit 30a9d3e Nov 4, 2025
20 checks passed
@perkinsjr perkinsjr deleted the eng-2076-enhancement-improve-onboarding-form-slug-generation branch November 4, 2025 14:18
@graphite-app
Copy link

graphite-app bot commented Nov 4, 2025

Graphite Automations

"Post a GIF when PR approved" took an action on this PR • (11/04/25)

1 gif was posted to this PR based on Andreas Thomas's automation.

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.

4 participants