Skip to content

Conversation

@wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Aug 20, 2025

Description

Fixes an issue where deeply updating Clerk component options would not trigger component updates in Vue UI components.

<script setup>
const appearance = ref({
  elements: {
    formButtonPrimary: {
      fontSize: 14,
      textTransform: 'none',
    },
  },
})

// Works when updating the whole value
appearance.value = {
  elements: {
    formButtonPrimary: {
      fontSize: 20,
      textTransform: 'none',
    },
  },
}

// Not reactive when deeply updating a value
appearance.value.elements.formButtonPrimary.fontSize = 20
</script>

<template>
  <SignIn :appearance />
</template>

This PR fixes the 2nd one

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

    • Deep updates to Clerk component options are now reactive, ensuring nested prop changes are reflected without remounts.
    • Improved stability for mount/unmount behavior; prop changes reliably propagate while components are mounted.
  • Chores

    • Added a changeset documenting a patch release for @clerk/vue.

@changeset-bot
Copy link

changeset-bot bot commented Aug 20, 2025

🦋 Changeset detected

Latest commit: 726e927

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

@wobsoriano wobsoriano changed the title fix(vue): Make Clerk component options reactive fix(vue): Make Clerk component options deeply reactive Aug 20, 2025
@vercel
Copy link

vercel bot commented Aug 20, 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 Aug 20, 2025 4:57pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 20, 2025

📝 Walkthrough

Walkthrough

  • Adds a new changeset file declaring a patch release for @clerk/vue, documenting a fix: deep updates to Clerk component options are now reactive.
  • Refactors ClerkHostRenderer reactivity: replaces onScopeDispose and toRef-based flow with onUnmounted, a boolean isPortalMounted, and a deep watch on props.props.
  • Mount/open now receive props.props directly; updates propagate via updateProps when props change.
  • Unmount and optional close are invoked on onUnmounted if the portal was mounted.
  • Imports adjusted to include onUnmounted and watch; watchEffect retained.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


🪧 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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 20, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 726e927

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: 0

🧹 Nitpick comments (9)
.changeset/friendly-penguins-wash.md (1)

5-5: Nit: Make the summary a touch more specific for consumers scanning release notes.

Consider mentioning Vue explicitly and giving a concrete example of a nested mutation that now works.

-Fixes an issue where deep updates to Clerk component options are not reactive.
+Fix: In Vue, deep mutations to Clerk component options (e.g. `appearance.elements.formButtonPrimary.fontSize = 20`) are now reactive and trigger UI updates.
packages/vue/src/components/ClerkHostRenderer.ts (8)

7-7: Avoid any in shared types.

Using any here weakens type-safety across all consumers of these props. Prefer unknown and narrow where needed.

-type AnyObject = Record<string, any>;
+type AnyObject = Record<string, unknown>;

39-43: Tighten the prop type for props to improve TS safety.

Currently type: Object erases structure. Use PropType<AnyObject> to keep typing consistent with the function prop signatures.

-    props: {
-      type: Object,
-      required: false,
-      default: () => ({}),
-    },
+    props: {
+      type: Object as PropType<AnyObject>,
+      required: false,
+      default: () => ({} as AnyObject),
+    },

2-2: Consider passing raw objects across the Vue boundary.

Passing Vue proxies to external SDK methods can be surprising. Using toRaw avoids accidental reactive leakage and makes behavior explicit.

-import { defineComponent, h, onUnmounted, ref, watch, watchEffect } from 'vue';
+import { defineComponent, h, onUnmounted, ref, watch, watchEffect, toRaw } from 'vue';

49-63: Mount/open calls: add minimal error handling and pass raw props.

  • Wrap mount/open to surface actionable errors to developers.
  • Pass toRaw(props.props) to avoid leaking proxies to the SDK.
-      if (props.mount) {
-        props.mount(portalRef.value, props.props);
-      }
-      if (props.open) {
-        props.open(props.props);
-      }
+      try {
+        if (props.mount) {
+          props.mount(portalRef.value, toRaw(props.props));
+        }
+        if (props.open) {
+          props.open(toRaw(props.props));
+        }
+      } catch (err: unknown) {
+        // Intentional: help devs diagnose integration issues
+        // eslint-disable-next-line no-console
+        console.error('[ClerkHostRenderer] Failed to mount/open Clerk component.', err);
+      }

Note: Using watchEffect here works; alternatively, onMounted would be a bit more idiomatic since you only need the DOM node once. Happy to provide a diff if you prefer that style.


64-72: Deep watch looks correct; add flush: 'post' and pass raw props.

flush: 'post' defers updates until after the current render, reducing chances of mid-render updates. Passing toRaw avoids proxies crossing the boundary.

-    watch(
+    watch(
       () => props.props,
-      newProps => {
+      newProps => {
         if (isPortalMounted && props.updateProps && portalRef.value) {
-          props.updateProps({ node: portalRef.value, props: newProps });
+          props.updateProps({ node: portalRef.value, props: toRaw(newProps) });
         }
       },
-      { deep: true },
+      { deep: true, flush: 'post' },
     );

74-83: Cleanup: guard and log errors during unmount/close.

Surface failures on teardown to aid debugging without being noisy in normal operation.

-    onUnmounted(() => {
-      if (isPortalMounted && portalRef.value) {
-        if (props.unmount) {
-          props.unmount(portalRef.value);
-        }
-        if (props.close) {
-          props.close();
-        }
-      }
-    });
+    onUnmounted(() => {
+      if (!isPortalMounted || !portalRef.value) return;
+      try {
+        if (props.unmount) {
+          props.unmount(portalRef.value);
+        }
+        if (props.close) {
+          props.close();
+        }
+      } catch (err: unknown) {
+        // eslint-disable-next-line no-console
+        console.error('[ClerkHostRenderer] Failed to unmount/close Clerk component.', err);
+      }
+    });

18-44: Public API docs/types.

This component is exported; consider adding/expanding JSDoc on function props (mount/unmount/open/close/updateProps) to clarify invocation timing and expected shapes. It helps downstream integrators and IDE hinting.

I can add succinct JSDoc with examples in a follow-up commit if you’d like.


49-72: Tests are missing for the deep reactivity regression.

Add a unit test asserting that mutating a nested property triggers updateProps with the updated structure.

Proposed test (Vue Test Utils + Vitest):

// packages/vue/src/components/__tests__/ClerkHostRenderer.spec.ts
import { defineComponent, h, ref } from 'vue';
import { mount } from '@vue/test-utils';
import { describe, it, expect, vi } from 'vitest';
import { ClerkHostRenderer } from '../ClerkHostRenderer';

describe('ClerkHostRenderer', () => {
  it('propagates deep mutations via updateProps', async () => {
    const appearance = ref({
      elements: { formButtonPrimary: { fontSize: 16 } },
    });

    const updateProps = vi.fn();

    const Wrapper = defineComponent(() =>
      () => h(ClerkHostRenderer, {
        mount: vi.fn(),
        unmount: vi.fn(),
        updateProps,
        props: appearance.value,
      }),
    );

    const wrapper = mount(Wrapper);
    // Deep mutation
    appearance.value.elements.formButtonPrimary.fontSize = 20;
    await wrapper.vm.$nextTick();

    expect(updateProps).toHaveBeenCalled();
    const lastCall = updateProps.mock.calls.at(-1)[0];
    expect(lastCall.props.elements.formButtonPrimary.fontSize).toBe(20);
  });
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • 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 c28d29c and 726e927.

📒 Files selected for processing (2)
  • .changeset/friendly-penguins-wash.md (1 hunks)
  • packages/vue/src/components/ClerkHostRenderer.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
.changeset/**

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/friendly-penguins-wash.md
**/*.{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/src/components/ClerkHostRenderer.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/src/components/ClerkHostRenderer.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/vue/src/components/ClerkHostRenderer.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/vue/src/components/ClerkHostRenderer.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/src/components/ClerkHostRenderer.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/src/components/ClerkHostRenderer.ts
**/*

⚙️ CodeRabbit Configuration File

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Files:

  • packages/vue/src/components/ClerkHostRenderer.ts
⏰ 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). (22)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (tanstack-react-router, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Static analysis
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
.changeset/friendly-penguins-wash.md (1)

1-6: Changeset looks good for a patch release.

Accurately scoped and matches the user-facing fix. No issues from a release automation standpoint.

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

64-72: Note on performance trade-offs of deep: true.

This achieves the goal (nested updates), but it can be costly for very large option trees. If perf becomes a concern, consider selectively watching only the relevant subtrees (e.g., appearance or elements) or instruct advanced users to replace object identities for large, batch updates.

Do we anticipate very large option objects in typical usage? If so, I can propose a selective watch strategy as a follow-up.

@wobsoriano wobsoriano merged commit aa9ff12 into main Aug 20, 2025
43 checks passed
@wobsoriano wobsoriano deleted the rob/vue-props-reactivity branch August 20, 2025 17:20
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.

5 participants