fix: add smooth scroll, focus-visible styles, and skeleton animation#700
fix: add smooth scroll, focus-visible styles, and skeleton animation#700saurabhhhcodes wants to merge 3 commits into
Conversation
…iboy#681) Check and increment of usedCount were non-atomic, allowing concurrent requests to all pass the limit check. Replaced with a single UPDATE that atomically increments usedCount WHERE maxUses is NULL or usedCount < maxUses. Returns 410 if no row matched the guard.
|
Someone is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel. A member of the Team first needs to authorize it. |
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
WalkthroughThe PR changes invite joining to use an atomic conditional update for ChangesAtomic Invite Usage Limit Enforcement
Global CSS UI Enhancements
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/app/api/invites/[token]/join/route.ts (1)
81-131: 🗄️ Data Integrity & Integration | 🟠 MajorFix the race condition in the invite join flow to prevent double-counted
usedCountincrements.The unique constraint on
(userEmail, classroomId)exists in the schema, but the concurrent race condition remains unresolved. Two simultaneous requests can both pass the membership check, both incrementusedCountsuccessfully, and then the second insert will fail due to the unique constraint—resulting in twousedCountincrements for a single membership creation and an unhandled error for the second user.Use
onConflictDoNothing()on the insert (lines 127–130) and handle the possibility of insertion failure to provide graceful user feedback instead of a generic error:const result = await db .insert(membershipsTable) .values({ userEmail: email, classroomId: inviteData.classroomId, role: "student", }) .onConflictDoNothing(); if (!result.rowsAffected) { return NextResponse.json({ success: true, alreadyMember: true, classroom: { /* ... */ }, }); }Alternatively, move the membership check after the
usedCountincrement within a transaction to ensure atomicity, or use row-level locking to prevent the select and insert from interleaving across concurrent requests.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/app/api/invites/`[token]/join/route.ts around lines 81 - 131, The insert operation on membershipsTable (lines 127-130) does not handle the race condition where two concurrent requests might both increment usedCount and then fail on insert. Add onConflictDoNothing() to the db.insert call to gracefully handle duplicate key violations. Then check the result's rowsAffected property—if it is zero, the user was already a member (conflict detected), so return the same success response with alreadyMember set to true that you return when an existing membership is found. This prevents the unhandled error and double-counted increments in concurrent scenarios.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@chat-system/styles/globals.css`:
- Line 82: The `scroll-behavior: smooth` rule on the `html` selector does not
respect user preferences for reduced motion, which is an accessibility issue.
Wrap the `scroll-behavior: smooth` declaration inside a media query with `@media
(prefers-reduced-motion: no-preference)` so that smooth scrolling is only
applied to users who have not indicated a preference for reduced motion. This
ensures the rule respects accessibility settings while still providing smooth
scrolling to users who prefer it.
- Around line 84-85: The newly defined .skeleton CSS class with the shimmer
animation in globals.css is not connected to the actual Skeleton component. The
Skeleton component in src/components/ui/skeleton.tsx uses Tailwind classes
(animate-pulse, rounded-md, bg-primary/10) instead of the .skeleton class.
Update the Skeleton component to apply the .skeleton class name so that the
shimmer animation effect is actually rendered on Skeleton UI elements throughout
the application.
In `@src/app/api/invites/`[token]/join/route.ts:
- Around line 104-131: The current database configuration uses the neon-http
driver which does not support transactions, causing a race condition where the
increment of usedCount in classroomInvitesTable and the insert into
membershipsTable execute as separate statements. Switch the Drizzle driver
configuration in src/configs/db.tsx from neon-http to neon-serverless, then wrap
both the update and insert operations (the classroomInvitesTable update and the
membershipsTable insert) in a single db.transaction() block to ensure atomicity
and prevent concurrent requests from incrementing usedCount without creating a
corresponding membership record.
---
Outside diff comments:
In `@src/app/api/invites/`[token]/join/route.ts:
- Around line 81-131: The insert operation on membershipsTable (lines 127-130)
does not handle the race condition where two concurrent requests might both
increment usedCount and then fail on insert. Add onConflictDoNothing() to the
db.insert call to gracefully handle duplicate key violations. Then check the
result's rowsAffected property—if it is zero, the user was already a member
(conflict detected), so return the same success response with alreadyMember set
to true that you return when an existing membership is found. This prevents the
unhandled error and double-counted increments in concurrent scenarios.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e3312fe0-0c6f-4111-921b-d6767499aa79
📒 Files selected for processing (2)
chat-system/styles/globals.csssrc/app/api/invites/[token]/join/route.ts
Signed-off-by: saurabhhhcodes <157192462+saurabhhhcodes@users.noreply.github.com>
|
CodeAnt AI is running Incremental review |
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
CodeAnt AI Incremental review completed. |
|
@saurabhhhcodes Resolve merge conflicts and ask for review again |
User description
CSS improvements:\n- Add smooth scroll behavior\n- Add visible focus-visible styles for keyboard accessibility\n- Add skeleton loading animation for async content
Summary by CodeRabbit
Release Notes
New Features
Improvements
Bug Fixes
CodeAnt-AI Description
Prevent invite link overuse and improve page interaction cues
What Changed
Impact
✅ Fewer invite link overuses✅ Clearer invite limit errors✅ Easier keyboard navigation💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.