') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); chore(astro): Remove deprecated `as` prop from button components by wobsoriano · Pull Request #5140 · clerk/javascript · GitHub
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 numberDiff line numberDiff 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?

@wobsorianowobsorianoFeb 12, 2025

Copy link
Copy Markdown
MemberAuthor

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
MemberAuthor

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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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;
};