Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/smart-rabbits-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@clerk/astro": minor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤔 Isn't this a breaking change?

@wobsoriano wobsoriano Feb 12, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good question! Hmmm originally when the as prop was added, we immediately did a follow up and introduced the asChild prop and documented that instead.

If we're going major on this one, I think we can skip this PR for now as it will be a waste of a major version bump. We can include this change in our next major release when we introduce more features / breaking change 👍🏼

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think this is a breaking change, we should schedule for the next major instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I will close this PR for now and revisit on our next major!

---

Remove deprecated `as` prop in the `<SignInButton />`, `<SignOutButton />`, and `<SignUpButton>` components. Please use the `asChild` prop if you are passing children to it.

Example:

```astro
---
import { SignInButton } from '@clerk/astro/components'
---

<SignInButton asChild>
<button>Custom sign in button</button>
</SignInButton>
```
21 changes: 7 additions & 14 deletions packages/astro/src/astro-components/unstyled/SignInButton.astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
---
import type { HTMLTag, Polymorphic } from 'astro/types'
import type { SignInButtonProps } from '@clerk/types'
import type { ButtonProps } from '../../types';
import { addUnstyledAttributeToFirstTag, logAsPropUsageDeprecation } from './utils'

type Props<Tag extends HTMLTag = 'button'> = Polymorphic<ButtonProps<Tag>> & SignInButtonProps;

import type { SignInButtonProps } from '@clerk/types';
import type { AsChildProps } from '../../types';
import { addUnstyledAttributeToFirstTag } from './utils';
import { generateSafeId } from '@clerk/astro/internal';

const safeId = generateSafeId();
type Props = AsChildProps<SignInButtonProps>;

if ('as' in Astro.props) {
logAsPropUsageDeprecation()
}
const safeId = generateSafeId();

const {
as: Tag = 'button',
asChild,
forceRedirectUrl,
fallbackRedirectUrl,
Expand Down Expand Up @@ -44,9 +37,9 @@ if (asChild) {
asChild ? (
<Fragment set:html={htmlElement} />
) : (
<Tag {...props} data-clerk-unstyled-id={safeId}>
<button {...props} data-clerk-unstyled-id={safeId}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

with asChild aren't we loosing data-clerk-unstyled-id ? is that ok ?

<slot>Sign in</slot>
</Tag >
</button >
)
}

Expand Down
21 changes: 7 additions & 14 deletions packages/astro/src/astro-components/unstyled/SignOutButton.astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
---
import type { HTMLTag, Polymorphic } from 'astro/types'
import type { SignOutOptions, Without } from '@clerk/types'
import type { ButtonProps } from '../../types';
import { addUnstyledAttributeToFirstTag, logAsPropUsageDeprecation } from './utils'
import type { SignOutOptions } from '@clerk/types';
import type { AsChildProps } from '../../types';
import { addUnstyledAttributeToFirstTag } from './utils';
import { generateSafeId } from '@clerk/astro/internal';

type Props<Tag extends HTMLTag = 'button'> = Polymorphic<SignOutOptions & ButtonProps<Tag>>

import { generateSafeId } from '@clerk/astro/internal'
type Props = AsChildProps<SignOutOptions>;

const safeId = generateSafeId();

if ('as' in Astro.props) {
logAsPropUsageDeprecation()
}

const {
as: Tag = 'button',
asChild,
redirectUrl = '/',
sessionId,
Expand All @@ -34,9 +27,9 @@ if (asChild) {
asChild ? (
<Fragment set:html={htmlElement} />
) : (
<Tag {...elementProps} data-clerk-unstyled-id={safeId}>
<button {...elementProps} data-clerk-unstyled-id={safeId}>
<slot>Sign out</slot>
</Tag >
</button >
)
}

Expand Down
21 changes: 7 additions & 14 deletions packages/astro/src/astro-components/unstyled/SignUpButton.astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
---
import type { HTMLTag, Polymorphic } from 'astro/types'
import type { SignUpButtonProps } from '@clerk/types'
import type { ButtonProps } from '../../types'
import { addUnstyledAttributeToFirstTag, logAsPropUsageDeprecation } from './utils'

type Props<Tag extends HTMLTag = 'button'> = Polymorphic<ButtonProps<Tag>> & SignUpButtonProps;

import type { SignUpButtonProps } from '@clerk/types';
import type { AsChildProps } from '../../types';
import { addUnstyledAttributeToFirstTag } from './utils';
import { generateSafeId } from '@clerk/astro/internal';

const safeId = generateSafeId();

if ('as' in Astro.props) {
logAsPropUsageDeprecation()
}

type Props = AsChildProps<SignUpButtonProps>;

const {
as: Tag = 'button',
asChild,
fallbackRedirectUrl,
forceRedirectUrl,
Expand Down Expand Up @@ -46,9 +39,9 @@ if (asChild) {
asChild ? (
<Fragment set:html={htmlElement} />
) : (
<Tag {...props} data-clerk-unstyled-id={safeId}>
<button {...props} data-clerk-unstyled-id={safeId}>
<slot>Sign up</slot>
</Tag >
</button >
)
}

Expand Down
14 changes: 0 additions & 14 deletions packages/astro/src/astro-components/unstyled/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,3 @@
export function addUnstyledAttributeToFirstTag(html: string, attributeValue: string): string {
return html.replace(/(<[^>]+)>/, `$1 data-clerk-unstyled-id="${attributeValue}">`);
}

/**
* Logs a deprecation warning when the 'as' prop is used.
*/
export function logAsPropUsageDeprecation() {
if (import.meta.env.PROD) {
return;
}

console.warn(
`[@clerk/astro] The 'as' prop is deprecated and will be removed in a future version. ` +
`Use the default slot with the 'asChild' prop instead. `,
);
}
11 changes: 1 addition & 10 deletions packages/astro/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ type ProtectProps =

export type { AstroClerkUpdateOptions, AstroClerkIntegrationParams, AstroClerkCreateInstanceParams, ProtectProps };

export type ButtonProps<Tag> = {
/**
* @deprecated The 'as' prop is deprecated and will be removed in a future version.
* Use the default slot with the 'asChild' prop instead.
* @example
* <SignInButton asChild>
* <button>Sign in</button>
* </SignInButton>
*/
as: Tag;
export type AsChildProps<T> = T & {
asChild?: boolean;
};