-
Notifications
You must be signed in to change notification settings - Fork 291
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: 03ab2e3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 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 |
9260c12
to
fa6e4a4
Compare
dts: false, | ||
esbuildPlugins: [ | ||
// Adds .vue files support | ||
vuePlugin() as EsbuildPlugin, |
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.
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
"unplugin-vue": "^5.2.1", | ||
"vue": "3.5.12", | ||
"vue-tsc": "^2.0.24" |
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.
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 { |
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.
I'm getting a transitive type dependency error because the SignInProps
is exported but not the TransferableOption
interface that it depends on
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
}, | ||
plugins: [vue()], |
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.
Required when testing .vue
SFC files
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.
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
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.
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
packages/vue/package.json
Outdated
@@ -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__", |
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.
Can you tell vue-tsc to ignore the test files so that we don't have to run rm -rf
?
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.
Updated! Got the idea here
<script setup lang="ts"> | ||
import { Portal } from '../uiComponents'; | ||
import { useClerk } from '../../composables'; | ||
import { SignInProps } from '@clerk/types'; |
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.
Nit: Add type
on the import
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.
added!
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:
With this PR, it also generate runtime type props:
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:
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: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.Type of change