Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
manudeli committed Dec 30, 2023
1 parent 4f3eed0 commit 83b7bcd
Show file tree
Hide file tree
Showing 26 changed files with 79 additions and 97 deletions.
1 change: 0 additions & 1 deletion configs/tsup/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ export const options: Options = {
dts: true,
minify: true,
treeshake: true,
clean: true,
}
23 changes: 7 additions & 16 deletions docs/v1/src/pages/docs/react/Suspense.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ Control multiple `<Suspense/>`s default fallback with `<SuspensiveProvider/>`. D

</Callout>

### Avoid Server side rendering (csrOnly)
### Avoid Server side rendering (clientOnly)

`<Suspense csrOnly/>` will return fallback in server. After mount(in client) return children. Since mount only happens on the client, server-side rendering can be avoided.
`<Suspense clientOnly/>` will return fallback in server. After mount(in client) return children. Since mount only happens on the client, server-side rendering can be avoided.

```tsx /csrOnly/
```tsx /clientOnly/
import { Suspense } from '@suspensive/react'

const Example = () => (
<Suspense csrOnly fallback={<Loading />}>
<Suspense clientOnly fallback={<Loading />}>
<Children />
</Suspense>
)
```

<Callout type='info'>

Migration support SSR gradually (`<Suspense csrOnly/>` -> `<Suspense/>`)
Migration support SSR gradually (`<Suspense clientOnly/>` -> `<Suspense/>`)

If you want to use Suspense working in both SSR/CSR, You can change `<Suspense csrOnly/>` to `<Suspense/>` gradually.
If you want to use Suspense working in both SSR/CSR, You can change `<Suspense clientOnly/>` to `<Suspense/>` gradually.

</Callout>

Expand All @@ -61,7 +61,7 @@ You can use withSuspense to wrap component by `<Suspense/>` easily.
we don't need to make unncessary code to wrap it if we use withSuspense like below.
withSuspense's 2nd parameter is props of `<Suspense/>` without children

```tsx /withSuspense.CSROnly/ /withSuspense/
```jsx /withSuspense/
import { withSuspense } from '@suspensive/react'

const Example = withSuspense(
Expand All @@ -72,13 +72,4 @@ const Example = withSuspense(
},
{ fallback: <Spinner /> }
)

const Example = withSuspense.CSROnly(
function Component() {
// code make suspending

return <>...</>
},
{ fallback: <Spinner /> }
)
```
23 changes: 7 additions & 16 deletions docs/v1/src/pages/docs/react/Suspense.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ Default fallback

</Callout>

### 서버사이드 렌더링을 피하기 (csrOnly)
### 서버사이드 렌더링을 피하기 (clientOnly)

`<Suspense csrOnly/>`는 서버에서는 fallback을 반환합니다. mount 후(클라이언트에서는) children을 반환합니다. mount는 클라이언트에서만 일어나기 때문에 서버사이드 렌더링을 피할 수 있습니다.
`<Suspense clientOnly/>`는 서버에서는 fallback을 반환합니다. mount 후(클라이언트에서는) children을 반환합니다. mount는 클라이언트에서만 일어나기 때문에 서버사이드 렌더링을 피할 수 있습니다.

```tsx /csrOnly/
```tsx /clientOnly/
import { Suspense } from '@suspensive/react'

const Example = () => (
<Suspense csrOnly fallback={<Loading />}>
<Suspense clientOnly fallback={<Loading />}>
<Children />
</Suspense>
)
```

<Callout type='info'>

SSR을 지원하도록 점진적으로 마이그레이션하기 (`<Suspense csrOnly/>` -> `<Suspense/>`)
SSR을 지원하도록 점진적으로 마이그레이션하기 (`<Suspense clientOnly/>` -> `<Suspense/>`)

React.Suspense를 SSR과 CSR에서 모두 사용하고 싶다면 `<Suspense csrOnly/>`에서 `<Suspense/>`로 점진적으로 마이그레이션하면 쉽게 적용할 수 있습니다.
React.Suspense를 SSR과 CSR에서 모두 사용하고 싶다면 `<Suspense clientOnly/>`에서 `<Suspense/>`로 점진적으로 마이그레이션하면 쉽게 적용할 수 있습니다.

</Callout>

Expand All @@ -60,7 +60,7 @@ withSuspense를 사용하면 컴포넌트를 `<Suspense/>`로 쉽게 래핑할
아래와 같이 withSuspense를 사용하면 이를 감싸기 위해 불필요한 코드를 만들 필요가 없습니다.
withSuspense의 두 번째 인자는 children이 없는 `<Suspense/>`의 props입니다.

```tsx /withSuspense.CSROnly/ /withSuspense/
```jsx /withSuspense/
import { withSuspense } from '@suspensive/react'

const Example = withSuspense(
Expand All @@ -71,13 +71,4 @@ const Example = withSuspense(
},
{ fallback: <Spinner /> }
)

const Example = withSuspense.CSROnly(
function Component() {
// code make suspending

return <>...</>
},
{ fallback: <Spinner /> }
)
```
2 changes: 1 addition & 1 deletion docs/v1/src/pages/docs/react/SuspensiveProvider.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const suspensive = new Suspensive({
},
suspense: {
fallback: <Spinner />,
csrOnly: false,
clientOnly: false,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/src/pages/docs/react/SuspensiveProvider.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const suspensive = new Suspensive({
},
suspense: {
fallback: <Spinner />,
csrOnly: false,
clientOnly: false,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/src/pages/docs/why.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Steps } from 'nextra/components'
If you have used React Suspense in SSR environment like Next.js, you may encounter error like below.
![Example banner](/img/suspense-in-ssr-error.png)

It's why [`<Suspense csrOnly/>`](/docs/react/Suspense) is added in this library.
It's why [`<Suspense clientOnly/>`](/docs/react/Suspense) is added in this library.

### ErrorBoundary more simply

Expand Down
2 changes: 1 addition & 1 deletion docs/v1/src/pages/docs/why.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Steps } from 'nextra/components'
React Suspense를 Next.js와 같은 서버사이드 렌더링 환경에서 사용해본 적이 있다면 아마 종종 아래 사진과 같은 에러를 겪게 된 적이 있을 겁니다.
![Example banner](/img/suspense-in-ssr-error.png)

이것이 [`<Suspense csrOnly/>`](/docs/react/Suspense)를 이 라이브러리에 추가한 이유입니다.
이것이 [`<Suspense clientOnly/>`](/docs/react/Suspense)를 이 라이브러리에 추가한 이유입니다.

### ErrorBoundary를 더욱 단순하게 사용하고 싶습니다.

Expand Down
2 changes: 1 addition & 1 deletion docs/v1/src/pages/index.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { HomePage } from '../components/HomePage.tsx'
},
{
title: 'Suspense in SSR easily',
desc: 'Suspensive provide CSROnly that make developer can adopt React Suspense gradually in Server-side rendering environment',
desc: 'Suspensive provide clientOnly that make developer can adopt React Suspense gradually in Server-side rendering environment',
},
]}
/>
2 changes: 1 addition & 1 deletion docs/v1/src/pages/index.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { HomePage } from '../components/HomePage.tsx'
},
{
title: '서버 사이드 렌더링에서도 쉽게',
desc: 'Suspensive는 개발자가 서버 사이드 렌더링 환경에서도 React Suspense를 점진적으로 채택할 수 있도록 CSROnly를 제공합니다',
desc: 'Suspensive는 개발자가 서버 사이드 렌더링 환경에서도 React Suspense를 점진적으로 채택할 수 있도록 clientOnly를 제공합니다',
},
]}
/>
12 changes: 6 additions & 6 deletions docs/v2/src/pages/docs/react/Suspense.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ Control multiple `<Suspense/>`s default fallback with `<SuspensiveProvider/>`. D

</Callout>

### Avoid Server side rendering (csrOnly)
### Avoid Server side rendering (clientOnly)

`<Suspense csrOnly/>` will return fallback in server. After mount(in client) return children. Since mount only happens on the client, server-side rendering can be avoided.
`<Suspense clientOnly/>` will return fallback in server. After mount(in client) return children. Since mount only happens on the client, server-side rendering can be avoided.

```tsx /csrOnly/
```tsx /clientOnly/
import { Suspense } from '@suspensive/react'

const Example = () => (
<Suspense csrOnly fallback={<Loading />}>
<Suspense clientOnly fallback={<Loading />}>
<Children />
</Suspense>
)
```

<Callout type='info'>

Migration support SSR gradually (`<Suspense csrOnly/>` -> `<Suspense/>`)
Migration support SSR gradually (`<Suspense clientOnly/>` -> `<Suspense/>`)

If you want to use Suspense working in both SSR/CSR, You can change `<Suspense csrOnly/>` to `<Suspense/>` gradually.
If you want to use Suspense working in both SSR/CSR, You can change `<Suspense clientOnly/>` to `<Suspense/>` gradually.

</Callout>
12 changes: 6 additions & 6 deletions docs/v2/src/pages/docs/react/Suspense.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ Default fallback

</Callout>

### 서버사이드 렌더링을 피하기 (csrOnly)
### 서버사이드 렌더링을 피하기 (clientOnly)

`<Suspense csrOnly/>`는 서버에서는 fallback을 반환합니다. mount 후(클라이언트에서는) children을 반환합니다. mount는 클라이언트에서만 일어나기 때문에 서버사이드 렌더링을 피할 수 있습니다.
`<Suspense clientOnly/>`는 서버에서는 fallback을 반환합니다. mount 후(클라이언트에서는) children을 반환합니다. mount는 클라이언트에서만 일어나기 때문에 서버사이드 렌더링을 피할 수 있습니다.

```tsx /csrOnly/
```tsx /clientOnly/
import { Suspense } from '@suspensive/react'

const Example = () => (
<Suspense csrOnly fallback={<Loading />}>
<Suspense clientOnly fallback={<Loading />}>
<Children />
</Suspense>
)
```

<Callout type='info'>

SSR을 지원하도록 점진적으로 마이그레이션하기 (`<Suspense csrOnly/>` -> `<Suspense/>`)
SSR을 지원하도록 점진적으로 마이그레이션하기 (`<Suspense clientOnly/>` -> `<Suspense/>`)

React.Suspense를 SSR과 CSR에서 모두 사용하고 싶다면 `<Suspense csrOnly/>`에서 `<Suspense/>`로 점진적으로 마이그레이션하면 쉽게 적용할 수 있습니다.
React.Suspense를 SSR과 CSR에서 모두 사용하고 싶다면 `<Suspense clientOnly/>`에서 `<Suspense/>`로 점진적으로 마이그레이션하면 쉽게 적용할 수 있습니다.

</Callout>
2 changes: 1 addition & 1 deletion docs/v2/src/pages/docs/react/SuspensiveProvider.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const suspensive = new Suspensive({
},
suspense: {
fallback: <Spinner />,
csrOnly: false,
clientOnly: false,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion docs/v2/src/pages/docs/react/SuspensiveProvider.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const suspensive = new Suspensive({
},
suspense: {
fallback: <Spinner />,
csrOnly: false,
clientOnly: false,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion docs/v2/src/pages/docs/why.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Steps } from 'nextra/components'
If you have used React Suspense in SSR environment like Next.js, you may encounter error like below.
![Example banner](/img/suspense-in-ssr-error.png)

It's why [`<Suspense csrOnly/>`](/docs/react/Suspense) is added in this library.
It's why [`<Suspense clientOnly/>`](/docs/react/Suspense) is added in this library.

### ErrorBoundary more simply

Expand Down
2 changes: 1 addition & 1 deletion docs/v2/src/pages/docs/why.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Steps } from 'nextra/components'
React Suspense를 Next.js와 같은 서버사이드 렌더링 환경에서 사용해본 적이 있다면 아마 종종 아래 사진과 같은 에러를 겪게 된 적이 있을 겁니다.
![Example banner](/img/suspense-in-ssr-error.png)

이것이 [`<Suspense csrOnly/>`](/docs/react/Suspense)를 이 라이브러리에 추가한 이유입니다.
이것이 [`<Suspense clientOnly/>`](/docs/react/Suspense)를 이 라이브러리에 추가한 이유입니다.

### ErrorBoundary를 더욱 단순하게 사용하고 싶습니다.

Expand Down
2 changes: 1 addition & 1 deletion docs/v2/src/pages/index.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { HomePage } from '../components/HomePage.tsx'
},
{
title: 'Suspense in SSR easily',
desc: 'Suspensive provide CSROnly that make developer can adopt React Suspense gradually in Server-side rendering environment',
desc: 'Suspensive provide clientOnly that make developer can adopt React Suspense gradually in Server-side rendering environment',
},
]}
/>
2 changes: 1 addition & 1 deletion docs/v2/src/pages/index.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { HomePage } from '../components/HomePage.tsx'
},
{
title: '서버 사이드 렌더링에서도 쉽게',
desc: 'Suspensive는 개발자가 서버 사이드 렌더링 환경에서도 React Suspense를 점진적으로 채택할 수 있도록 CSROnly를 제공합니다',
desc: 'Suspensive는 개발자가 서버 사이드 렌더링 환경에서도 React Suspense를 점진적으로 채택할 수 있도록 clientOnly를 제공합니다',
},
]}
/>
2 changes: 1 addition & 1 deletion packages/react-query/src/QueryAsyncBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (process.env.NODE_ENV !== 'production') {
*/
export const QueryAsyncBoundary = Object.assign(BaseQueryAsyncBoundary, {
/**
* @deprecated Use `<QueryErrorBoundary/>`, `<Suspense csrOnly/>` at once instead
* @deprecated Use `<QueryErrorBoundary/>`, `<Suspense clientOnly/>` at once instead
*/
CSROnly,
})
25 changes: 13 additions & 12 deletions packages/react/src/AsyncBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export interface AsyncBoundaryProps
export const AsyncBoundary = Object.assign(
(() => {
const BaseAsyncBoundary = forwardRef<ComponentRef<typeof ErrorBoundary>, AsyncBoundaryProps>(
({ csrOnly, pendingFallback, rejectedFallback, children, ...errorBoundaryProps }, resetRef) => (
({ clientOnly, pendingFallback, rejectedFallback, children, ...errorBoundaryProps }, resetRef) => (
<ErrorBoundary {...errorBoundaryProps} ref={resetRef} fallback={rejectedFallback}>
<Suspense csrOnly={csrOnly} fallback={pendingFallback}>
<Suspense clientOnly={clientOnly} fallback={pendingFallback}>
{children}
</Suspense>
</ErrorBoundary>
Expand All @@ -35,18 +35,19 @@ export const AsyncBoundary = Object.assign(
})(),
{
/**
* @deprecated Use `<Suspense csrOnly />` and `<ErrorBoundary/>` instead
* @deprecated Use `<Suspense clientOnly />` and `<ErrorBoundary/>` instead
*/
CSROnly: (() => {
const CSROnly = forwardRef<ComponentRef<typeof ErrorBoundary>, Omit<AsyncBoundaryProps, 'csrOnly'>>(
({ pendingFallback, rejectedFallback, children, ...errorBoundaryProps }, resetRef) => (
<ErrorBoundary {...errorBoundaryProps} ref={resetRef} fallback={rejectedFallback}>
<Suspense csrOnly fallback={pendingFallback}>
{children}
</Suspense>
</ErrorBoundary>
)
)
const CSROnly = forwardRef<
ComponentRef<typeof ErrorBoundary>,
Omit<AsyncBoundaryProps, keyof Pick<SuspenseProps, 'clientOnly'>>
>(({ pendingFallback, rejectedFallback, children, ...errorBoundaryProps }, resetRef) => (
<ErrorBoundary {...errorBoundaryProps} ref={resetRef} fallback={rejectedFallback}>
<Suspense clientOnly fallback={pendingFallback}>
{children}
</Suspense>
</ErrorBoundary>
))
if (process.env.NODE_ENV !== 'production') {
CSROnly.displayName = 'AsyncBoundary.CSROnly'
}
Expand Down
12 changes: 6 additions & 6 deletions packages/react/src/Suspense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type PropsWithDevMode } from './utility-types'
import { noop } from './utils'

export interface SuspenseProps extends PropsWithDevMode<SuspenseDevModeOptions>, ReactSuspenseProps {
csrOnly?: boolean
clientOnly?: boolean
}

const SuspenseContextFallback = () => useContext(SuspenseDefaultOptionsContext).fallback
Expand All @@ -16,11 +16,11 @@ const SuspenseContextFallback = () => useContext(SuspenseDefaultOptionsContext).
*/
export const Suspense = Object.assign(
(() => {
const SuspenseCSROnly = (props: ReactSuspenseProps) =>
const SuspenseClientOnly = (props: ReactSuspenseProps) =>
useIsClient() ? <ReactSuspense {...props} /> : <>{props.fallback}</>

const Suspense = ({ csrOnly, devMode, children, fallback = <SuspenseContextFallback /> }: SuspenseProps) => {
const DefinedSuspense = csrOnly ? SuspenseCSROnly : ReactSuspense
const Suspense = ({ clientOnly, devMode, children, fallback = <SuspenseContextFallback /> }: SuspenseProps) => {
const DefinedSuspense = clientOnly ? SuspenseClientOnly : ReactSuspense
return (
<DefinedSuspense fallback={fallback}>
{children}
Expand All @@ -36,14 +36,14 @@ export const Suspense = Object.assign(
})(),
{
/**
* @deprecated Use `<Suspense csrOnly/>` instead
* @deprecated Use `<Suspense clientOnly/>` instead
*/
CSROnly: (() => {
const CSROnly = ({
devMode,
children,
fallback = <SuspenseContextFallback />,
}: Omit<SuspenseProps, 'csrOnly'>) =>
}: Omit<SuspenseProps, keyof Pick<SuspenseProps, 'clientOnly'>>) =>
useIsClient() ? (
<ReactSuspense fallback={fallback}>
{children}
Expand Down
Loading

0 comments on commit 83b7bcd

Please sign in to comment.