Skip to content

Commit 224fc11

Browse files
committed
fix: add clientOnly() deprecation warning
1 parent f87917e commit 224fc11

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/vike-react/src/helpers/clientOnly.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// TODO/soon: add deprecation warning in favor of <ClientOnly>
21
// TO-DO/breaking-change: remove it
32

43
export { clientOnly }
@@ -13,6 +12,7 @@ import React, {
1312
type ComponentType,
1413
type ReactNode,
1514
} from 'react'
15+
import { assertWarning } from '../utils/assert.js'
1616

1717
/**
1818
* Load and render a component only on the client-side.
@@ -22,6 +22,8 @@ import React, {
2222
function clientOnly<T extends ComponentType<any>>(
2323
load: () => Promise<{ default: T } | T>,
2424
): ComponentType<ComponentProps<T> & { fallback?: ReactNode }> {
25+
assertWarning(false, 'clientOnly() is deprecated — use <ClientOnly> https://vike.dev/ClientOnly')
26+
2527
if (!globalThis.__VIKE__IS_CLIENT) {
2628
return (props) => <>{props.fallback}</>
2729
} else {

packages/vike-react/src/utils/assert.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ export function assert(condition: unknown): asserts condition {
22
if (condition) return
33
throw new Error('You stumbled upon a vike-react bug, reach out on GitHub.')
44
}
5+
6+
export function assertWarning(condition: unknown, message: string) {
7+
if (condition) return
8+
console.warn(new Error(message))
9+
}

0 commit comments

Comments
 (0)