Skip to content

Commit da39eea

Browse files
committed
make Show strict in astro
1 parent f7609b1 commit da39eea

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

integration/templates/astro-node/src/pages/server-islands.astro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import Layout from '../layouts/Layout.astro';
55

66
<Layout title='Page is only accessible by members'>
77
<div class='w-full flex justify-center flex-col'>
8-
<Show server:defer>
8+
<Show
9+
server:defer
10+
when='signedIn'
11+
>
912
<p slot='fallback'>Loading</p>
1013
<Show when={{ role: 'org:admin' }}>
1114
<h1 class='text-2xl text-center'>I'm an admin</h1>

integration/tests/astro/components.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ testAgainstRunningApps({ withPattern: ['astro.node.withCustomRoles'] })('basic f
351351
await u.po.signIn.waitForMounted();
352352
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeAdmin.email, password: fakeAdmin.password });
353353
await u.po.expect.toBeSignedIn();
354-
await expect(u.page.getByText('Not a member')).toBeVisible();
354+
await expect(u.page.getByText("I'm a member")).toBeVisible();
355355
});
356356

357357
// --- react/components
@@ -449,7 +449,7 @@ testAgainstRunningApps({ withPattern: ['astro.node.withCustomRoles'] })('basic f
449449
await u.po.signIn.waitForMounted();
450450
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeAdmin2.email, password: fakeAdmin2.password });
451451
await u.po.expect.toBeSignedIn();
452-
await expect(u.page.getByText('Not a member')).toBeVisible();
452+
await expect(u.page.getByText("I'm a member")).toBeVisible();
453453
});
454454

455455
test('renders components and keep internal routing behavior when view transitions is enabled', async ({
@@ -491,7 +491,7 @@ testAgainstRunningApps({ withPattern: ['astro.node.withCustomRoles'] })('basic f
491491
// This is being investigated upstream with the Astro team. The test is commented out for now
492492
// to unblock development and will be revisited once the root cause is resolved.
493493
// await expect(u.page.getByText('Loading')).toBeHidden();
494-
await expect(u.page.getByText('Not an admin')).toBeVisible();
494+
await expect(u.page.getByText('Loading')).toBeVisible();
495495

496496
// Sign in as admin user
497497
await u.page.goToRelative('/sign-in');
@@ -509,6 +509,6 @@ testAgainstRunningApps({ withPattern: ['astro.node.withCustomRoles'] })('basic f
509509
// This is being investigated upstream with the Astro team. The test is commented out for now
510510
// to unblock development and will be revisited once the root cause is resolved.
511511
// await expect(u.page.getByText('Loading')).toBeHidden();
512-
await expect(u.page.getByText("I'm an admin")).toBeVisible();
512+
await expect(u.page.getByText("I'm an admin")).toBeVisible({ timeout: 15_000 });
513513
});
514514
});

integration/tests/astro/hybrid.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ testAgainstRunningApps({ withPattern: ['astro.static.withCustomRoles'] })(
108108

109109
await u.page.goToRelative('/only-members');
110110

111-
await expect(u.page.getByText('Not a member')).toBeVisible();
111+
await expect(u.page.getByText("I'm a member")).toBeVisible();
112112
});
113113
},
114114
);

packages/astro/src/astro-components/control/Show.astro

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ type Props = ShowProps & {
1414
class?: string;
1515
};
1616
17-
const { isStatic, ...props } = Astro.props;
17+
const { isStatic, when, ...rest } = Astro.props;
18+
19+
if (typeof when === 'undefined') {
20+
throw new Error('@clerk/astro: <Show /> requires a `when` prop.');
21+
}
22+
23+
const props = { ...rest, when };
1824
1925
const ShowComponent = isStaticOutput(isStatic) ? ShowCSR : ShowSSR;
2026

packages/astro/src/react/controlComponents.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export type ShowProps = React.PropsWithChildren<
5757
>;
5858

5959
export const Show = ({ children, fallback, treatPendingAsSignedOut, when }: ShowProps) => {
60+
if (typeof when === 'undefined') {
61+
throw new Error('@clerk/astro: <Show /> requires a `when` prop.');
62+
}
63+
6064
const { has, isLoaded, userId } = useAuth({ treatPendingAsSignedOut });
6165

6266
if (!isLoaded) {

0 commit comments

Comments
 (0)