Skip to content

feat: scope support in usePreferences hook#1405

Merged
rohanchkrabrty merged 4 commits intomainfrom
scope-use-preferences
Feb 24, 2026
Merged

feat: scope support in usePreferences hook#1405
rohanchkrabrty merged 4 commits intomainfrom
scope-use-preferences

Conversation

@rohanchkrabrty
Copy link
Contributor

Summary

Updated the usePreferences hook to align with the new preferences API that supports scoped preferences (e.g., per-organization).

Changes

  • Added optional scopeType and scopeId parameters to the hook for scoped preference queries
  • Updated Preference type to include scopeType and scopeId fields
  • Exposed fetchPreferencesStatus and updatePreferencesStatus from the hook return
  • Passed scope parameters to listCurrentUserPreferences request

Technical Details

  • The listCurrentUserPreferences API now accepts scopeType and scopeId to filter preferences by context (e.g., "app/organization" + org ID)
  • All changes are backward-compatible — existing consumers don't need updates since new params/fields are optional

@rohanchkrabrty rohanchkrabrty self-assigned this Feb 23, 2026
@vercel
Copy link

vercel bot commented Feb 23, 2026

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

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Feb 24, 2026 6:40am

@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

Warning

Rate limit exceeded

@rohanchkrabrty has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between baeae3a and 493aac6.

⛔ Files ignored due to path filters (1)
  • web/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • web/sdk/package.json
📝 Walkthrough

Walkthrough

This pull request adds build configuration updates, expands UI and form library dependencies, extends the TypeScript compiler options with JSX configuration, and enhances the usePreferences hook to accept scope parameters and expose query/mutation status properties.

Changes

Cohort / File(s) Summary
Build and Project Configuration
.gitignore, web/sdk/tsconfig.json, web/sdk/package.json
Added node_modules/ and .next/ to gitignore, configured JSX compiler option, updated @raystack/proton dependency, and added devDependencies for @radix-ui/react-form, @stitches/react, react-loading-skeleton, and sonner.
React Hook Enhancement
web/sdk/react/hooks/usePreferences.ts
Extended usePreferences to accept optional scopeType and scopeId parameters, added fetchPreferencesStatus and updatePreferencesStatus to return type, imported UseMutationResult and UseQueryResult types, and forwarded scope parameters to query initialization via ListCurrentUserPreferencesRequestSchema.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes


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.

@coveralls
Copy link

coveralls commented Feb 23, 2026

Pull Request Test Coverage Report for Build 22339673600

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 39.848%

Totals Coverage Status
Change from base Build 22336016583: 0.0%
Covered Lines: 13595
Relevant Lines: 34117

💛 - Coveralls

Copy link

@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

🧹 Nitpick comments (3)
web/sdk/react/hooks/usePreferences.ts (3)

37-45: Consider validating that scopeType and scopeId are provided together.

If a caller passes scopeType without scopeId (or vice versa), the request will include an incomplete scope context. Depending on the API contract, this could silently return unscoped results or fail unexpectedly. A runtime guard or a type-level constraint would make this more robust.

Option A: Runtime guard
 export function usePreferences({
   autoFetch = true,
   scopeType,
   scopeId
 }: {
   autoFetch?: boolean;
   scopeType?: string;
   scopeId?: string;
 } = {}): UsePreferences {
+  if ((scopeType && !scopeId) || (!scopeType && scopeId)) {
+    console.warn('frontier:sdk:: usePreferences: scopeType and scopeId should be provided together');
+  }
Option B: Type-level constraint (discriminated union)
type UsePreferencesOptions =
  | { autoFetch?: boolean; scopeType?: undefined; scopeId?: undefined }
  | { autoFetch?: boolean; scopeType: string; scopeId: string };

89-101: Duplicate error logging — onError in useMutation and catch in updatePreferences both log.

When updatePreferencesMutation rejects, the onError callback on line 81–86 logs the error, and then the catch block on lines 96–100 logs the same error again before rethrowing. This results in double console output for every mutation failure.

♻️ Remove one of the duplicate error handlers

Either remove the onError callback from useMutation (since updatePreferences already handles errors), or remove the try/catch logging and let onError be the single logging site:

   const updatePreferences = useCallback(async (preferences: Preference[]) => {
-    try {
-      const req = create(CreateCurrentUserPreferencesRequestSchema, {
-        bodies: preferences
-      });
-      await updatePreferencesMutation(req);
-    } catch (err) {
-      console.error(
-        'frontier:sdk:: There is problem with updating user preferences'
-      );
-      console.error(err);
-      throw err;
-    }
+    const req = create(CreateCurrentUserPreferencesRequestSchema, {
+      bodies: preferences
+    });
+    await updatePreferencesMutation(req);
   }, [updatePreferencesMutation]);

The onError on the mutation already handles logging. If you need the caller to catch, mutateAsync rejects naturally.


104-118: The composite status field doesn't account for error states.

The status computation maps to 'loading' | 'fetching' | 'idle', but both the query and mutation can be in an error state. Consumers relying on status alone won't know about failures — they'd need to check fetchPreferencesStatus or updatePreferencesStatus separately. This is pre-existing behavior, but now that you're exposing the granular statuses, consider documenting or aligning the composite status type.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3395789 and baeae3a.

⛔ Files ignored due to path filters (1)
  • web/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • .gitignore
  • web/sdk/package.json
  • web/sdk/react/hooks/usePreferences.ts
  • web/sdk/tsconfig.json

@rohanchkrabrty rohanchkrabrty merged commit 51d98c2 into main Feb 24, 2026
8 checks passed
@rohanchkrabrty rohanchkrabrty deleted the scope-use-preferences branch February 24, 2026 06:44
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.

3 participants