-
Notifications
You must be signed in to change notification settings - Fork 419
fix(vue): Make Clerk component options deeply reactive #6588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 726e927 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthrough
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this 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: Avoidanyin shared types.Using
anyhere weakens type-safety across all consumers of these props. Preferunknownand narrow where needed.-type AnyObject = Record<string, any>; +type AnyObject = Record<string, unknown>;
39-43: Tighten the prop type forpropsto improve TS safety.Currently
type: Objecterases structure. UsePropType<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
toRawavoids 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
watchEffecthere works; alternatively,onMountedwould 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; addflush: 'post'and pass raw props.
flush: 'post'defers updates until after the current render, reducing chances of mid-render updates. PassingtoRawavoids 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
updatePropswith 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.
📒 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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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
Useconst assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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 ofdeep: 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.,
appearanceorelements) 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.
Description
Fixes an issue where deeply updating Clerk component options would not trigger component updates in Vue UI components.
This PR fixes the 2nd one
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Bug Fixes
Chores