Skip to content

Fix/collab bug#22

Merged
Kripu77 merged 2 commits intomainfrom
fix/collab-bug
Mar 7, 2026
Merged

Fix/collab bug#22
Kripu77 merged 2 commits intomainfrom
fix/collab-bug

Conversation

@Kripu77
Copy link
Owner

@Kripu77 Kripu77 commented Mar 7, 2026

Summary by CodeRabbit

  • New Features

    • Enhanced collaboration session initialization with improved creator state management to ensure proper session preparation during collaboration setup.
  • Tests

    • Refactored collaboration dialog timeout test to use more reliable asynchronous assertions instead of timer mocking.

@vercel
Copy link

vercel bot commented Mar 7, 2026

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

Project Deployment Actions Updated (UTC)
thinkix Ready Ready Preview, Comment Mar 7, 2026 3:16am

@Kripu77 Kripu77 marked this pull request as ready for review March 7, 2026 03:15
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

📝 Walkthrough

Walkthrough

This pull request implements a pending-creator flag mechanism for collaboration sessions. New methods prepareAsCreator() and checkAndConsumePendingCreator() are added to coordinate session state via sessionStorage, allowing the page component to mark a room as pending creator before navigation and check/consume that flag during initialization. A test is updated to use asynchronous assertions instead of fake timers.

Changes

Cohort / File(s) Summary
Collaboration Session & Integration
packages/collaboration/src/hooks/use-collaboration-session.ts, app/page.tsx
Introduces pending-creator flag mechanism with sessionStorage helpers (setPendingCreatorFlag, getAndClearPendingCreatorFlag). Exposes prepareAsCreator(roomId) and checkAndConsumePendingCreator() methods on the collaboration session API. Page component integrates these methods to gate initiator determination logic on the pending creator signal.
Test Updates
tests/components/collaboration-start-dialog.test.tsx
Unskips and rewrites the "reverts to Copy after timeout" test, replacing fake timer controls with waitFor-based assertions for monitoring UI state transitions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A flag in storage, per room so neat,
Prepares creators before they fleet,
When checked and consumed with logic true,
Collaboration flows through and through! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic, using 'Fix/collab bug' without describing what specific issue is being addressed or what the fix entails. Replace with a more specific title that describes the actual fix, such as 'Add pending creator flag mechanism for collaboration sessions' or 'Fix collaboration session initialization flow'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/collab-bug

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

@github-actions
Copy link

github-actions bot commented Mar 7, 2026

⚠️ Test Results

Metric Coverage
Lines 0%
Functions 93.3%
Branches 78.86%
Statements 91.26%
Average 65.9%

📦 Download Coverage Report

How to view coverage report
  1. Download the coverage artifact from the link above
  2. Extract the ZIP file
  3. Open index.html in your browser

Commit: 4be7b56dd78ea5a19aa29da8cee38b3a705ff487

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)
app/page.tsx (1)

138-142: ⚠️ Potential issue | 🟠 Major

Same dependency array issue with session object.

This effect also includes the entire session object in its dependency array, which has the same re-render concern as noted above.

🔧 Proposed fix
+  const { wasDisabled, markAsDisabled } = session;
+
   useEffect(() => {
-    if (!roomFromUrl && session.wasDisabled === false) {
-      session.markAsDisabled();
+    if (!roomFromUrl && wasDisabled === false) {
+      markAsDisabled();
     }
-  }, [roomFromUrl, session]);
+  }, [roomFromUrl, wasDisabled, markAsDisabled]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/page.tsx` around lines 138 - 142, The useEffect depends on the entire
session object which triggers unnecessary re-renders; destructure the specific
properties you need (e.g., const { wasDisabled, markAsDisabled } = session) and
update the effect to use those instead, then change the dependency array to
[roomFromUrl, wasDisabled, markAsDisabled] so only the needed
primitives/functions control re-running the effect (if markAsDisabled isn't
stable, wrap it in a useCallback or reference it from a ref first).
🧹 Nitpick comments (1)
tests/components/collaboration-start-dialog.test.tsx (1)

111-130: Inconsistent timer strategy between tests in the same describe block.

The "handles clipboard error gracefully" test still uses fake timers while the "reverts to Copy after timeout" test now uses real timers. This inconsistency could lead to confusion and potential issues if tests run in different orders.

Consider standardizing on one approach for all tests in the copy functionality describe block.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/components/collaboration-start-dialog.test.tsx` around lines 111 - 130,
The tests in the "copy functionality" describe block use inconsistent timer
handling: the "handles clipboard error gracefully" test uses vi.useFakeTimers()
then vi.runAllTimersAsync() but the "reverts to Copy after timeout" test uses
real timers; make them consistent by switching both tests to the same timer
strategy (prefer using fake timers for deterministic behavior), ensure each test
calls vi.useFakeTimers() at start and vi.useRealTimers() (or
vi.useFakeTimers().clearAllTimers equivalent) in a finally/afterEach cleanup,
and keep the logger spy restore (loggerSpy.mockRestore()) inside the same test
cleanup so symbols like vi.useFakeTimers, vi.runAllTimersAsync,
vi.useRealTimers, and loggerSpy are handled deterministically across tests in
the describe block.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/page.tsx`:
- Around line 118-125: The effect re-runs every render because the whole session
object is in the dependency array; destructure only the used properties/methods
from the useCollaborationSession result (e.g., const { isInitiator,
checkAndConsumePendingCreator, markAsInitiator, clearDisabled } = session) and
replace session in the effect dependencies with roomFromUrl, isInitiator,
checkAndConsumePendingCreator, markAsInitiator, clearDisabled; apply the same
pattern to the other effects that currently depend on the entire session object
(the ones using session.wasDisabled and similar calls) so each effect only
depends on the specific primitives/methods it uses.

---

Outside diff comments:
In `@app/page.tsx`:
- Around line 138-142: The useEffect depends on the entire session object which
triggers unnecessary re-renders; destructure the specific properties you need
(e.g., const { wasDisabled, markAsDisabled } = session) and update the effect to
use those instead, then change the dependency array to [roomFromUrl,
wasDisabled, markAsDisabled] so only the needed primitives/functions control
re-running the effect (if markAsDisabled isn't stable, wrap it in a useCallback
or reference it from a ref first).

---

Nitpick comments:
In `@tests/components/collaboration-start-dialog.test.tsx`:
- Around line 111-130: The tests in the "copy functionality" describe block use
inconsistent timer handling: the "handles clipboard error gracefully" test uses
vi.useFakeTimers() then vi.runAllTimersAsync() but the "reverts to Copy after
timeout" test uses real timers; make them consistent by switching both tests to
the same timer strategy (prefer using fake timers for deterministic behavior),
ensure each test calls vi.useFakeTimers() at start and vi.useRealTimers() (or
vi.useFakeTimers().clearAllTimers equivalent) in a finally/afterEach cleanup,
and keep the logger spy restore (loggerSpy.mockRestore()) inside the same test
cleanup so symbols like vi.useFakeTimers, vi.runAllTimersAsync,
vi.useRealTimers, and loggerSpy are handled deterministically across tests in
the describe block.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f1fd39b3-4e58-41bc-af6c-6127f0468a07

📥 Commits

Reviewing files that changed from the base of the PR and between d5e5adc and ae49df2.

📒 Files selected for processing (3)
  • app/page.tsx
  • packages/collaboration/src/hooks/use-collaboration-session.ts
  • tests/components/collaboration-start-dialog.test.tsx

@Kripu77 Kripu77 merged commit dc1f337 into main Mar 7, 2026
9 checks passed
@Kripu77 Kripu77 deleted the fix/collab-bug branch March 7, 2026 03:30
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