Skip to content
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

chore(vue,types): Add initial support for SFC files to improve runtime prop checking #4902

Merged
merged 18 commits into from
Jan 16, 2025

Conversation

wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Jan 15, 2025

Description

This PR adds initial support for Vue Single-File Components starting with the <SignIn /> component.

Right now we're using render functions to build out our Clerk components and this Esbuild plugin to generate prop types (e.g. SignInProps) to runtime props. This way, we can have the Vue SDK component prop in sync with prop types imported from @clerk/types.

The problem above is that it generates props but without runtime type validation (only type validation in IDE). Example output:

Screenshot 2025-01-15 at 12 24 13 PM

With this PR, it also generate runtime type props:

Screenshot 2025-01-15 at 11 59 07 AM

Everything should still function the same. I'll do a follow up PR for the rest of the components 🫡

Additional context

We're also doing this to unblock the release of the new sign-in-or-up feature which is not properly working with the current setup. If you have something like this:

<SignIn withSignUp />
<SignIn with-sign-up />
<SignIn :with-sign-up="true" />

The 3rd one above will only work as we're forcefully setting the value. The first 2 ones are expected to output true as the value but instead outputs an empty string:

Screenshot 2025-01-15 at 12 59 31 PM

This results in a falsy value and depending on the logic, might have some unexpected results. It happens because it does not have a proper runtime type.

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:

Copy link

vercel bot commented Jan 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 4:24pm

Copy link

changeset-bot bot commented Jan 15, 2025

🦋 Changeset detected

Latest commit: 03ab2e3

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

This PR includes changesets to release 22 packages
Name Type
@clerk/types Patch
@clerk/vue Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/clerk-js Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/clerk-expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/shared Patch
@clerk/tanstack-start Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/ui Patch
@clerk/chrome-extension 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 force-pushed the rob/fix-vue-components-runtime-props branch from 9260c12 to fa6e4a4 Compare January 15, 2025 20:06
@wobsoriano wobsoriano marked this pull request as ready for review January 15, 2025 20:28
Comment on lines +17 to +20
dts: false,
esbuildPlugins: [
// Adds .vue files support
vuePlugin() as EsbuildPlugin,
Copy link
Member Author

@wobsoriano wobsoriano Jan 15, 2025

Choose a reason for hiding this comment

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

This vuePlugin transforms .vue files to JavaScript. We also turned off dts generation of tsup so that the vue-tsc module will generate it instead

@wobsoriano wobsoriano changed the title chore(vue,types): Add initial support for SFC files to improve runtime prop checking chore(vue): Add initial support for SFC files to improve runtime prop checking Jan 15, 2025
Comment on lines +61 to +63
"unplugin-vue": "^5.2.1",
"vue": "3.5.12",
"vue-tsc": "^2.0.24"
Copy link
Member Author

Choose a reason for hiding this comment

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

unplugin-vue - esbuild plugin to tranform .vue files to JS
vue-tsc - dts emit with .vue file support

@@ -990,7 +990,7 @@ export type SignInCombinedProps = RoutingOptions & {
LegacyRedirectProps &
AfterSignOutUrl;

interface TransferableOption {
export interface TransferableOption {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm getting a transitive type dependency error because the SignInProps is exported but not the TransferableOption interface that it depends on

@wobsoriano wobsoriano changed the title chore(vue): Add initial support for SFC files to improve runtime prop checking chore(vue,types): Add initial support for SFC files to improve runtime prop checking Jan 15, 2025
@clerk clerk deleted a comment from clerk-cookie Jan 15, 2025
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
},
plugins: [vue()],
Copy link
Member Author

@wobsoriano wobsoriano Jan 15, 2025

Choose a reason for hiding this comment

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

Required when testing .vue SFC files

@clerk clerk deleted a comment from clerk-cookie Jan 15, 2025
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the <SignIn /> component and functions the same as before only that we moved it into a single-file component (SFC) and that the Esbuild Vue plugin (check tsup config) can convert the typescript type props to runtime type props

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the <SignInButton /> component and functions the same as before only that we moved it into a single-file component (SFC) and that the Esbuild Vue plugin (check tsup config) can convert the typescript type props to runtime type props

@@ -41,10 +41,11 @@
"dist"
],
"scripts": {
"build": "tsup",
"build": "tsup --onSuccess \"pnpm build:dts\"",
"build:dts": "vue-tsc --declaration --emitDeclarationOnly && rm -rf dist/components/__tests__",
Copy link
Member

Choose a reason for hiding this comment

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

Can you tell vue-tsc to ignore the test files so that we don't have to run rm -rf?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated! Got the idea here

<script setup lang="ts">
import { Portal } from '../uiComponents';
import { useClerk } from '../../composables';
import { SignInProps } from '@clerk/types';
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Add type on the import

Copy link
Member Author

Choose a reason for hiding this comment

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

added!

@wobsoriano wobsoriano merged commit 4af3538 into main Jan 16, 2025
29 checks passed
@wobsoriano wobsoriano deleted the rob/fix-vue-components-runtime-props branch January 16, 2025 16:31
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.

4 participants