Skip to content

Conversation

@reneshen0328
Copy link
Contributor

@reneshen0328 reneshen0328 commented Feb 10, 2026

Summary

Issue

  • When an item is initially created without a shared link, Content Sharing V2 is not able to create a shared link. The network request never happens.
  • The root cause was that useSharingService would not create the sharing service when sharedLink was null, preventing the "Create Shared Link" action from working

Solution

  • Adds hasSharedLink flag to createSharingService to track whether a shared link currently exists
  • Operations that require an existing shared link (changeSharedLinkAccess, changeSharedLinkPermission, updateSharedLink, deleteSharedLink) now properly reject with a 404 error when no shared link exists, while createSharedLink works regardless of the flag
    • Without this, unified-share-modal package handles error internally as well. The Promise.reject calls serve as a guard against invalid states. Even if the consumer doesn't explicitly handle the rejection, it prevents the code from making unnecessary API calls when there's no shared link.

Test plan

  • Verify creating a new shared link works when no shared link exists
  • Verify modifying an existing shared link (access, permissions, settings) works correctly
  • Verify deleting an existing shared link works correctly
  • Verify attempting to modify/delete a non-existent shared link returns a 404 error

Summary by CodeRabbit

  • Bug Fixes

    • Shared-link operations now validate link presence and return proper "not found" errors when no shared link exists.
  • Behavioral Changes

    • Sharing service creation and access now consistently respect whether a shared link is present, altering when service calls occur.
  • Tests

    • Expanded and parameterized tests cover rejection scenarios and both shared-link present/absent cases.

@reneshen0328 reneshen0328 requested review from a team as code owners February 10, 2026 23:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

Walkthrough

This PR adds a hasSharedLink flag propagated from the hook into createSharingService and enforces 404 guards in update/delete/access/permission sharing operations when no shared link exists.

Changes

Cohort / File(s) Summary
Service Implementation
src/elements/content-sharing/sharingService.ts
Added hasSharedLink to CreateSharingServiceArgs and createSharingService args; added pre-checks that reject with 404 ("Shared link not found") in changeSharedLinkAccess, changeSharedLinkPermission, updateSharedLink, and deleteSharedLink when hasSharedLink is false.
Hook Implementation
src/elements/content-sharing/hooks/useSharingService.ts
Relaxed gating so itemApiInstance no longer requires sharedLink; use optional chaining for sharedLink fields; propagate hasSharedLink: !!sharedLink?.url into createSharingService; adjusted memo deps.
Tests
src/elements/content-sharing/__tests__/sharingService.test.ts, src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts
Added parameterized tests for hasSharedLink true/false; added 404 rejection tests for guarded methods; updated expectations to verify hasSharedLink propagation and that mocks are not called when flag is false.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Hook as useSharingService
    participant FileAPI
    participant Service as SharingService
    participant Server

    Client->>Hook: request sharing service (item, sharedLink?)
    Hook->>FileAPI: getFileAPI(...) (if item present)
    FileAPI-->>Hook: itemApiInstance
    Hook->>Service: createSharingService({ api: itemApiInstance, hasSharedLink: !!sharedLink?.url, options... })
    Service-->>Hook: SharingService instance
    Client->>Service: e.g., updateSharedLink / deleteSharedLink / changeAccess
    alt hasSharedLink == true
        Service->>Server: perform API call
        Server-->>Service: success
    else hasSharedLink == false
        Service-->>Client: reject 404 "Shared link not found"
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • tjuanitas
  • jfox-box
  • jpan-box

Poem

🐰 A tiny flag hops into place,
Guarding links in code and space,
When url's gone, the methods stop,
No needless calls — a tidy hop,
Tests cheer on this gentle pace 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(content-sharing): Fix create shared link bug' directly summarizes the main issue fixed: enabling shared link creation when no initial shared link exists, which aligns with the primary changeset objective.
Description check ✅ Passed The PR description includes a clear summary with issue and solution, detailed explanation of the fix, and a test plan with checkmarks. However, it lacks specific implementation details (what files changed, API signatures) expected in comprehensive PR documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ 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 fix-content-sharing-create-shared-link

No actionable comments were generated in the recent review. 🎉


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.

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

🤖 Fix all issues with AI agents
In `@src/elements/content-sharing/sharingService.ts`:
- Around line 22-23: Make hasSharedLink required on CreateSharingServiceArgs
(change hasSharedLink?: boolean to hasSharedLink: boolean) so callers like
useSharingService and any future call sites must pass the flag, and update those
callers accordingly; also extract the repeated Object.assign(new Error('Shared
link not found'), { status: 404 }) into a single helper (e.g.,
createSharedLinkNotFoundError or SHARED_LINK_NOT_FOUND_ERROR) and use that
helper in the four guarded methods changeSharedLinkAccess,
changeSharedLinkPermission, updateSharedLink, and deleteSharedLink to remove
duplication.
🧹 Nitpick comments (2)
src/elements/content-sharing/sharingService.ts (1)

39-42: Consider extracting the repeated 404 rejection into a helper.

The same Promise.reject(Object.assign(new Error('Shared link not found'), { status: 404 })) pattern is duplicated in four methods. A small helper would reduce repetition and ensure consistency if the error shape ever changes.

Suggested helper
+const rejectSharedLinkNotFound = () =>
+    Promise.reject(Object.assign(new Error('Shared link not found'), { status: 404 }));
+
 const changeSharedLinkAccess = async (access: string): Promise<void> => {
     if (!hasSharedLink) {
-        return Promise.reject(Object.assign(new Error('Shared link not found'), { status: 404 }));
+        return rejectSharedLinkNotFound();
     }

Then reuse in the other three guards.

src/elements/content-sharing/hooks/useSharingService.ts (1)

72-78: hasSharedLink: !!sharedLink?.url is a sound heuristic but worth a brief comment.

Using the presence of url as the canonical indicator of an existing shared link is reasonable — an object without a URL hasn't been persisted server-side yet. A short inline comment would help future maintainers understand why url (rather than just the object's truthiness) is the criteria.

@reneshen0328 reneshen0328 force-pushed the fix-content-sharing-create-shared-link branch from 1ac27c6 to 672161f Compare February 11, 2026 00:07
Copy link
Contributor

@tjuanitas tjuanitas left a comment

Choose a reason for hiding this comment

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

👏

@mergify mergify bot added the queued label Feb 11, 2026
@mergify mergify bot merged commit 8cffb09 into master Feb 11, 2026
12 checks passed
@mergify mergify bot deleted the fix-content-sharing-create-shared-link branch February 11, 2026 00:30
@mergify
Copy link
Contributor

mergify bot commented Feb 11, 2026

Merge Queue Status

Rule: Automatic strict merge


  • Entered queue2026-02-11 00:30 UTC
  • Checks passed · in-place
  • Merged2026-02-11 00:30 UTC · at 672161f9d156ee3065f30a7a936a105ba2f26f21

This pull request spent 7 seconds in the queue, with no time running CI.

Required conditions to merge

@mergify mergify bot removed the queued label Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants