Skip to content

Conversation

wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Sep 5, 2025

Description

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Bug Fixes
    • Prevents runtime error when installing the Clerk Vue plugin without options.
    • Provides clearer, scoped error messages when using Clerk Vue without the plugin installed, with a direct docs link.
  • Tests
    • Added tests covering plugin-installed vs. not-installed scenarios.
  • Tooling
    • Introduced a test setup file and updated test configuration for consistent environment variables.
  • Chores
    • Added a changeset to publish a patch release for @clerk/vue.

Copy link

changeset-bot bot commented Sep 5, 2025

🦋 Changeset detected

Latest commit: d2d3155

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clerk/vue Patch
@clerk/nuxt Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link

vercel bot commented Sep 5, 2025

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

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Sep 5, 2025 5:46pm

Copy link
Contributor

coderabbitai bot commented Sep 5, 2025

Walkthrough

Adds a named-source parameter to useClerkContext with centralized error handling via errorThrower and updated docs link. Updates all callsites to pass their identifier. Makes plugin.install resilient to undefined options. Introduces a unit test for missing-plugin errors, plus Vitest setup/config. Adds a changeset for a patch release.

Changes

Cohort / File(s) Summary
Clerk context hook update
packages/vue/src/composables/useClerkContext.ts
Adds source: string parameter, integrates errorThrower, updates error message and docs URL; returns context or throws via errorThrower.
Callsite updates to pass source
packages/vue/src/composables/use*.ts, packages/vue/src/components/controlComponents.ts
Replace useClerkContext() with useClerkContext('<hook/component name>') across Auth, Clerk, Organization, Session, SessionList, SignIn, SignUp, User, and RedirectToSignIn. No logic changes otherwise.
Plugin install hardening
packages/vue/src/plugin.ts
Safely destructures initialState from possibly undefined options.
Tests and test setup
packages/vue/src/composables/__tests__/useClerkContext.test.ts,
packages/vue/vitest.config.ts, packages/vue/vitest.setup.ts
New test validates error when plugin not installed and success when installed; adds Vitest setup file preloading PACKAGE_NAME/PACKAGE_VERSION; references setup in config.
Changeset
.changeset/fuzzy-rivers-tell.md
Adds patch release note for @clerk/vue highlighting improved error when plugin not installed.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as App Component
  participant Hook as useAuth/useUser/...
  participant Ctx as useClerkContext(source)
  participant Vue as Vue inject()
  participant Err as errorThrower

  Dev->>Hook: call composable
  Hook->>Ctx: useClerkContext("useAuth")
  Ctx->>Vue: inject(ClerkContextKey)
  alt Context found
    Vue-->>Ctx: ctx
    Ctx-->>Hook: ctx
    Hook-->>Dev: computed refs
  else Context missing
    Ctx->>Err: throw("@clerk/vue: useAuth can only be used when the Vue plugin is installed. ...")
    Err-->>Dev: Error thrown
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibbled through the context grass,
Named each path that I would pass.
If plugins hide, I thump—beware!
A clearer squeak of error air.
With tests to tuck me in at night,
I hop a patch—release in sight. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rob/better-vue-nuxt-plugin-error-message

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Sep 5, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6719

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6719

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6719

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6719

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6719

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6719

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6719

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6719

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6719

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6719

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6719

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6719

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6719

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6719

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6719

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6719

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6719

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6719

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6719

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6719

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6719

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6719

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6719

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6719

commit: d2d3155

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)
packages/vue/src/plugin.ts (1)

41-57: Fix unsafe access when pluginOptions is undefined

You guard initialState with pluginOptions || {}, but still read pluginOptions.sdkMetadata, which will throw if pluginOptions is undefined. Merge with a default and use optional chaining.

Apply:

-    const { initialState } = pluginOptions || {};
+    const { initialState } = pluginOptions ?? {};

     const options = {
-      ...pluginOptions,
-      sdkMetadata: pluginOptions.sdkMetadata || SDK_METADATA,
+      ...(pluginOptions ?? {}),
+      sdkMetadata: pluginOptions?.sdkMetadata ?? SDK_METADATA,
     } as LoadClerkJsScriptOptions;
🧹 Nitpick comments (4)
packages/vue/src/composables/useSignIn.ts (1)

33-39: De-duplicate the hook name string

Use a single SOURCE constant for both telemetry and error provenance to prevent drift.

Apply:

 export const useSignIn: UseSignIn = () => {
-  const { clerk, clientCtx } = useClerkContext('useSignIn');
+  const SOURCE = 'useSignIn' as const;
+  const { clerk, clientCtx } = useClerkContext(SOURCE);

   const unwatch = watch(clerk, value => {
     if (value) {
-      value.telemetry?.record(eventMethodCalled('useSignIn'));
+      value.telemetry?.record(eventMethodCalled(SOURCE));
       unwatch();
     }
   });
packages/vue/src/composables/useUser.ts (1)

35-47: Optional: avoid hardcoded hook name

Mirror the useSignIn pattern with a SOURCE constant to avoid copy-paste mistakes across files.

 export const useUser: UseUser = () => {
-  const { userCtx } = useClerkContext('useUser');
+  const SOURCE = 'useUser' as const;
+  const { userCtx } = useClerkContext(SOURCE);
packages/vue/src/composables/__tests__/useClerkContext.test.ts (2)

9-23: Solid negative-path coverage; minor resilience tweak

Test is precise and hides Vue’s inject warning. Consider building the expected prefix from PACKAGE_NAME to avoid hardcoding '@clerk/vue'.

-    expect(() => render(Component)).toThrow(
-      '@clerk/vue: useAuth can only be used when the Vue plugin is installed. Learn more: https://clerk.com/docs/references/vue/clerk-plugin',
-    );
+    const prefix = `${globalThis.PACKAGE_NAME}: `;
+    expect(() => render(Component)).toThrow(
+      `${prefix}useAuth can only be used when the Vue plugin is installed. Learn more: https://clerk.com/docs/references/vue/clerk-plugin`,
+    );

25-45: Prevent accidental network/script loads during tests

When installing the real plugin, plugin.ts may attempt to load ClerkJS in JSDOM. Mock the browser loader to a resolved promise to keep tests hermetic.

Add near the top of this test file (before imports that use the plugin), or in a dedicated test setup:

vi.mock('../../utils/loadClerkJsScript', () => ({
  loadClerkJsScript: () => Promise.resolve(),
}));
vi.mock('../../utils/inBrowser', () => ({
  inBrowser: () => false, // or true if you prefer, since load is mocked anyway
}));

Alternatively, add afterEach(() => vi.restoreAllMocks()) to the suite to ensure mocks/spies are reset.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4a5bd7a and 5b75dde.

📒 Files selected for processing (15)
  • .changeset/fuzzy-rivers-tell.md (1 hunks)
  • packages/vue/src/components/controlComponents.ts (1 hunks)
  • packages/vue/src/composables/__tests__/useClerkContext.test.ts (1 hunks)
  • packages/vue/src/composables/useAuth.ts (1 hunks)
  • packages/vue/src/composables/useClerk.ts (1 hunks)
  • packages/vue/src/composables/useClerkContext.ts (1 hunks)
  • packages/vue/src/composables/useOrganization.ts (1 hunks)
  • packages/vue/src/composables/useSession.ts (1 hunks)
  • packages/vue/src/composables/useSessionList.ts (1 hunks)
  • packages/vue/src/composables/useSignIn.ts (1 hunks)
  • packages/vue/src/composables/useSignUp.ts (1 hunks)
  • packages/vue/src/composables/useUser.ts (1 hunks)
  • packages/vue/src/plugin.ts (1 hunks)
  • packages/vue/vitest.config.ts (1 hunks)
  • packages/vue/vitest.setup.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/vue/vitest.setup.ts
  • packages/vue/src/composables/useUser.ts
  • packages/vue/src/composables/__tests__/useClerkContext.test.ts
  • packages/vue/src/composables/useSession.ts
  • packages/vue/vitest.config.ts
  • packages/vue/src/composables/useSignIn.ts
  • packages/vue/src/composables/useSessionList.ts
  • packages/vue/src/composables/useClerk.ts
  • packages/vue/src/composables/useClerkContext.ts
  • packages/vue/src/composables/useSignUp.ts
  • packages/vue/src/composables/useOrganization.ts
  • packages/vue/src/plugin.ts
  • packages/vue/src/composables/useAuth.ts
  • packages/vue/src/components/controlComponents.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/vue/vitest.setup.ts
  • packages/vue/src/composables/useUser.ts
  • packages/vue/src/composables/__tests__/useClerkContext.test.ts
  • packages/vue/src/composables/useSession.ts
  • packages/vue/vitest.config.ts
  • packages/vue/src/composables/useSignIn.ts
  • packages/vue/src/composables/useSessionList.ts
  • packages/vue/src/composables/useClerk.ts
  • packages/vue/src/composables/useClerkContext.ts
  • packages/vue/src/composables/useSignUp.ts
  • packages/vue/src/composables/useOrganization.ts
  • packages/vue/src/plugin.ts
  • packages/vue/src/composables/useAuth.ts
  • packages/vue/src/components/controlComponents.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/vue/vitest.setup.ts
  • packages/vue/src/composables/useUser.ts
  • packages/vue/src/composables/__tests__/useClerkContext.test.ts
  • packages/vue/src/composables/useSession.ts
  • packages/vue/vitest.config.ts
  • packages/vue/src/composables/useSignIn.ts
  • packages/vue/src/composables/useSessionList.ts
  • packages/vue/src/composables/useClerk.ts
  • packages/vue/src/composables/useClerkContext.ts
  • packages/vue/src/composables/useSignUp.ts
  • packages/vue/src/composables/useOrganization.ts
  • packages/vue/src/plugin.ts
  • packages/vue/src/composables/useAuth.ts
  • packages/vue/src/components/controlComponents.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/vue/vitest.setup.ts
  • packages/vue/src/composables/useUser.ts
  • packages/vue/src/composables/__tests__/useClerkContext.test.ts
  • packages/vue/src/composables/useSession.ts
  • packages/vue/vitest.config.ts
  • packages/vue/src/composables/useSignIn.ts
  • packages/vue/src/composables/useSessionList.ts
  • packages/vue/src/composables/useClerk.ts
  • packages/vue/src/composables/useClerkContext.ts
  • packages/vue/src/composables/useSignUp.ts
  • packages/vue/src/composables/useOrganization.ts
  • packages/vue/src/plugin.ts
  • packages/vue/src/composables/useAuth.ts
  • packages/vue/src/components/controlComponents.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/vue/vitest.setup.ts
  • packages/vue/src/composables/useUser.ts
  • packages/vue/src/composables/__tests__/useClerkContext.test.ts
  • packages/vue/src/composables/useSession.ts
  • packages/vue/vitest.config.ts
  • packages/vue/src/composables/useSignIn.ts
  • packages/vue/src/composables/useSessionList.ts
  • packages/vue/src/composables/useClerk.ts
  • packages/vue/src/composables/useClerkContext.ts
  • packages/vue/src/composables/useSignUp.ts
  • packages/vue/src/composables/useOrganization.ts
  • packages/vue/src/plugin.ts
  • packages/vue/src/composables/useAuth.ts
  • packages/vue/src/components/controlComponents.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/vue/vitest.setup.ts
  • packages/vue/src/composables/useUser.ts
  • packages/vue/src/composables/__tests__/useClerkContext.test.ts
  • packages/vue/src/composables/useSession.ts
  • packages/vue/vitest.config.ts
  • packages/vue/src/composables/useSignIn.ts
  • packages/vue/src/composables/useSessionList.ts
  • packages/vue/src/composables/useClerk.ts
  • packages/vue/src/composables/useClerkContext.ts
  • packages/vue/src/composables/useSignUp.ts
  • packages/vue/src/composables/useOrganization.ts
  • packages/vue/src/plugin.ts
  • packages/vue/src/composables/useAuth.ts
  • packages/vue/src/components/controlComponents.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Unit tests should use Jest or Vitest as the test runner.

Files:

  • packages/vue/src/composables/__tests__/useClerkContext.test.ts
**/__tests__/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)

**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces

Files:

  • packages/vue/src/composables/__tests__/useClerkContext.test.ts
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/fuzzy-rivers-tell.md
🧬 Code graph analysis (11)
packages/vue/src/composables/useUser.ts (1)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
packages/vue/src/composables/__tests__/useClerkContext.test.ts (2)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
packages/vue/src/plugin.ts (1)
  • clerkPlugin (39-123)
packages/vue/src/composables/useSession.ts (1)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
packages/vue/src/composables/useSignIn.ts (1)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
packages/vue/src/composables/useSessionList.ts (1)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
packages/vue/src/composables/useClerk.ts (1)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
packages/vue/src/composables/useClerkContext.ts (2)
packages/vue/src/keys.ts (1)
  • ClerkInjectionKey (5-5)
packages/vue/src/errors/errorThrower.ts (1)
  • errorThrower (6-6)
packages/vue/src/composables/useSignUp.ts (1)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
packages/vue/src/composables/useOrganization.ts (1)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
packages/vue/src/composables/useAuth.ts (1)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
packages/vue/src/components/controlComponents.ts (1)
packages/vue/src/composables/useClerkContext.ts (1)
  • useClerkContext (6-16)
⏰ 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). (1)
  • GitHub Check: Integration Tests (billing, chrome)
🔇 Additional comments (14)
.changeset/fuzzy-rivers-tell.md (1)

1-6: Changeset looks good

Patch bump and concise summary are appropriate for this scope.

packages/vue/vitest.config.ts (1)

8-8: Good addition of setupFiles

The relative path is correct given file locations; this will ensure globals are stubbed before tests run.

packages/vue/vitest.setup.ts (2)

1-6: LGTM on test setup

Using vi.stubGlobal is a clean way to supply PACKAGE_NAME/VERSION for runtime code in tests.


5-6: resolveJsonModule already enabled
The packages/vue/tsconfig.json has compilerOptions.resolveJsonModule set to true, so importing package.json works as expected.

packages/vue/src/composables/useClerk.ts (1)

21-22: Passing source to useClerkContext is correct

This aligns with the improved error messaging and central handling.

packages/vue/src/composables/useOrganization.ts (1)

56-56: Clearer, actionable error context — nice.

Passing 'useOrganization' into useClerkContext improves the missing-plugin error and debuggability.

packages/vue/src/composables/useSignUp.ts (1)

33-33: Good: scoped source name for error messaging.

Supplying 'useSignUp' to useClerkContext aligns with the new API and yields clearer guidance when the plugin is absent.

packages/vue/src/composables/useAuth.ts (2)

77-77: LGTM: explicit source improves diagnostics.

useClerkContext('useAuth') matches the updated signature and enhances the error text.


77-77: All useClerkContext calls include a source string and the plugin docs link is present.

packages/vue/src/composables/useSessionList.ts (1)

35-35: Nice consistency with the new API.

Providing 'useSessionList' to useClerkContext keeps errors specific and actionable.

packages/vue/src/composables/useSession.ts (1)

36-36: Consistent, clearer errors — approved.

useClerkContext('useSession') adheres to the refactor and improves DX on misconfiguration.

packages/vue/src/components/controlComponents.ts (1)

40-40: Approve: No remaining zero-argument useClerkContext calls found
Search confirms there are no zero-argument calls to useClerkContext in packages/vue.

packages/vue/src/composables/useUser.ts (1)

35-35: LGTM

Passing 'useUser' to useClerkContext aligns with the new signature and improves error clarity.

packages/vue/src/composables/useClerkContext.ts (1)

6-16: Add explicit return type for useClerkContext

Per TS guidelines, public APIs should declare explicit return types. Derive the injected context type from the InjectionKey to avoid importing internal types.

 import { inject } from 'vue';
+import type { InjectionKey } from 'vue';

 import { errorThrower } from '../errors/errorThrower';
 import { ClerkInjectionKey } from '../keys';

+type ClerkContext = typeof ClerkInjectionKey extends InjectionKey<infer T> ? T : never;
-export function useClerkContext(source: string) {
+export function useClerkContext(source: string): ClerkContext {
   const ctx = inject(ClerkInjectionKey);

   if (!ctx) {
     return errorThrower.throw(
       `${source} can only be used when the Vue plugin is installed. Learn more: https://clerk.com/docs/references/vue/clerk-plugin`,
     );
   }

   return ctx;
 }

errorThrower.throw is already typed to return never, so the annotated return type is satisfied.

Comment on lines 20 to 24
export const useClerk = () => {
const { clerk } = useClerkContext();
const { clerk } = useClerkContext('useClerk');

return clerk;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add an explicit return type for the public API

Per repo guidelines, declare the return type.

Example:

+import type { ShallowRef } from 'vue';
+import type { Clerk } from '@clerk/types';
-export const useClerk = () => {
+export const useClerk = (): ShallowRef<Clerk | null> => {
   const { clerk } = useClerkContext('useClerk');
   return clerk;
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const useClerk = () => {
const { clerk } = useClerkContext();
const { clerk } = useClerkContext('useClerk');
return clerk;
};
import type { ShallowRef } from 'vue';
import type { Clerk } from '@clerk/types';
export const useClerk = (): ShallowRef<Clerk | null> => {
const { clerk } = useClerkContext('useClerk');
return clerk;
};
🤖 Prompt for AI Agents
In packages/vue/src/composables/useClerk.ts around lines 20 to 24, the exported
useClerk function is missing an explicit return type; update the signature to
declare the return type (for example: export const useClerk = ():
ReturnType<typeof useClerkContext>['clerk'] => { ... }), or alternatively
import/declare the concrete Clerk type and use that, and ensure any necessary
type imports are added at the top of the file.

@wobsoriano wobsoriano enabled auto-merge (squash) September 5, 2025 17:50
@wobsoriano wobsoriano merged commit a8e7794 into main Sep 5, 2025
37 of 38 checks passed
@wobsoriano wobsoriano deleted the rob/better-vue-nuxt-plugin-error-message branch September 5, 2025 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants