Skip to content

fix(react): define default prop of each components(Delay, Suspense)#709

Merged
manudeli merged 11 commits into
toss:mainfrom
ssi02014:react/Delay
Feb 8, 2024
Merged

fix(react): define default prop of each components(Delay, Suspense)#709
manudeli merged 11 commits into
toss:mainfrom
ssi02014:react/Delay

Conversation

@ssi02014
Copy link
Copy Markdown
Contributor

@ssi02014 ssi02014 commented Feb 7, 2024

Overview

I was looking at the Delay component in @suspensive/react and it seems that if we utilize the generic type of PropsWithChildren, we can remove the unnecessary OmitKeyOf utility type.

type PropsWithChildren<P = unknown> = P & { children?: ReactNode | undefined };

Also, I added test code for the fallback of the Delay component.

PR Checklist

  • I did below actions if need
  1. I read the Contributing Guide
  2. I added documents and tests.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 7, 2024

🦋 Changeset detected

Latest commit: b9348bf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@suspensive/react Patch
@suspensive/react-query Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
beta ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 8, 2024 2:57am
main ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 8, 2024 2:57am
visualization ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 8, 2024 2:57am

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 7, 2024

Deploy Preview for suspensive-org ready!

Name Link
🔨 Latest commit b9348bf
🔍 Latest deploy log https://app.netlify.com/sites/suspensive-org/deploys/65c442369185c6000729a18b
😎 Deploy Preview https://deploy-preview-709--suspensive-org.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 7, 2024

Deploy Preview for suspensive-next-streaming-react-query ready!

Name Link
🔨 Latest commit b9348bf
🔍 Latest deploy log https://app.netlify.com/sites/suspensive-next-streaming-react-query/deploys/65c44236aefb970008d48169
😎 Deploy Preview https://deploy-preview-709--suspensive-next-streaming-react-query.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 7, 2024

Codecov Report

Merging #709 (b9348bf) into main (5fb61ec) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #709   +/-   ##
=======================================
  Coverage   83.76%   83.76%           
=======================================
  Files          31       31           
  Lines         505      505           
  Branches      116      115    -1     
=======================================
  Hits          423      423           
  Misses         72       72           
  Partials       10       10           
Components Coverage Δ
@suspensive/react 97.56% <ø> (ø)
@suspensive/react-query 0.00% <ø> (ø)
@suspensive/react-await 100.00% <ø> (ø)
@suspensive/react-image 23.52% <ø> (ø)

@vercel vercel Bot temporarily deployed to Preview – visualization February 7, 2024 19:30 Inactive
@vercel vercel Bot temporarily deployed to Preview – main February 7, 2024 19:32 Inactive
Comment thread packages/react/src/contexts/DefaultOptionsContexts.ts Outdated
@vercel vercel Bot temporarily deployed to Preview – beta February 7, 2024 19:36 Inactive
@vercel vercel Bot temporarily deployed to Preview – main February 7, 2024 19:37 Inactive
@vercel vercel Bot temporarily deployed to Preview – visualization February 7, 2024 19:39 Inactive
Comment thread packages/react/src/Delay.spec.tsx Outdated
import type { OmitKeyOf } from '../utility-types'

export const DelayDefaultPropsContext = createContext<OmitKeyOf<DelayProps, 'children'>>({
export const DelayDefaultPropsContext = createContext<DelayProps>({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In my opinion, if this is named for meaning props of Delay, because Delay have children prop, we should use PropsWithChildren in DelayProps internally

We can check ErrorBoundaryProps contain type PropsWithChildren internally
https://github.com/bvaughn/react-error-boundary/blob/master/src/types.ts#L18C33-L26

Because of this reason, we had to omit children of each components(Delay, Suspense) intentionally. because we didn't want library users to use default prop for children prop. children prop should be set by use case each time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@manudeli Aha I understand the intent, thanks for the quick feedback 🙏

Comment thread packages/react/src/contexts/DefaultOptionsContexts.ts Outdated
Comment thread packages/react/src/Delay.spec.tsx
Comment thread packages/react/src/Delay.tsx Outdated
Comment thread packages/react/src/Delay.tsx Outdated
Comment thread packages/react/src/contexts/DefaultOptionsContexts.ts Outdated
Comment thread packages/react/src/wrap.tsx Outdated
@vercel vercel Bot temporarily deployed to Preview – visualization February 8, 2024 01:30 Inactive
@vercel vercel Bot temporarily deployed to Preview – main February 8, 2024 01:31 Inactive
@vercel vercel Bot temporarily deployed to Preview – beta February 8, 2024 01:32 Inactive
ssi02014 and others added 5 commits February 8, 2024 10:35
Co-authored-by: Jonghyeon Ko <jonghyeon.ko@wesang.com>
Co-authored-by: Jonghyeon Ko <jonghyeon.ko@wesang.com>
Co-authored-by: Jonghyeon Ko <jonghyeon.ko@wesang.com>
Co-authored-by: Jonghyeon Ko <jonghyeon.ko@wesang.com>
Comment thread .changeset/swift-foxes-exist.md Outdated
@manudeli manudeli changed the title refactor(react): improved Delay Type and Add Test Code fix(react): define default prop of each components(Delay, Suspense) Feb 8, 2024
@vercel vercel Bot temporarily deployed to Preview – main February 8, 2024 01:45 Inactive

vi.advanceTimersByTime(ms('0.5s'))

await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument())
Copy link
Copy Markdown
Member

@manudeli manudeli Feb 8, 2024

Choose a reason for hiding this comment

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

How about more strictly by timeout option of waitFor?

Suggested change
await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument())
await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument(), {
timeout: ms('0.5s'),
})

https://testing-library.com/docs/dom-testing-library/api-async/#waitfor

because default timeout is 1000ms

image

Copy link
Copy Markdown
Contributor Author

@ssi02014 ssi02014 Feb 8, 2024

Choose a reason for hiding this comment

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

@manudeli
I know that option doesn't make much sense if we use a fake timer, but do you think it would be better to add it?

  it('should render fallback content initially and then the actual text after the delay', async () => {
    render(
      <Delay ms={ms('2s')} fallback={<p role="paragraph">fallback</p>}>
        {TEXT}
      </Delay>
    )
    // vi.advanceTimersByTime(ms('1s'))

    expect(screen.queryByRole('paragraph')).toBeInTheDocument()

    // vi.advanceTimersByTime(ms('1s'))

    await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument(), { timeout: ms('2.1s') }) // Success
    // await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument(), { timeout: ms('2s') }) // Failed
  })

In the above case, the timeout of waitFor is valid.

  it('should render fallback content initially and then the actual text after the delay', async () => {
    render(
      <Delay ms={ms('2s')} fallback={<p role="paragraph">fallback</p>}>
        {TEXT}
      </Delay>
    )
    // vi.advanceTimersByTime(ms('1s'))

    expect(screen.queryByRole('paragraph')).toBeInTheDocument()

    // vi.advanceTimersByTime(ms('1s'))

    await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument()) // Failed
  })

스크린샷 2024-02-08 오전 11 36 40

However, if we don't use fake time as shown above and don't specify the timeout option, the test will fail because, as you said, the default value of timeout is 1000ms.

  it('should render fallback content initially and then the actual text after the delay', async () => {
    render(
      <Delay ms={ms('2s')} fallback={<p role="paragraph">fallback</p>}>
        {TEXT}
      </Delay>
    )
    vi.advanceTimersByTime(ms('1s'))

    expect(screen.queryByRole('paragraph')).toBeInTheDocument()

    vi.advanceTimersByTime(ms('1s'))

    await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument()) // Success
  })

If we use a fake timer, we don't necessarily need the timeout option - the above test will work fine.

Copy link
Copy Markdown
Contributor Author

@ssi02014 ssi02014 Feb 8, 2024

Choose a reason for hiding this comment

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

I've given a large time value in the example above for illustration purposes (because the default value for timeout is 1000ms) 🙏

Copy link
Copy Markdown
Contributor Author

@ssi02014 ssi02014 Feb 8, 2024

Choose a reason for hiding this comment

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

@vercel vercel Bot temporarily deployed to Preview – visualization February 8, 2024 01:46 Inactive
@vercel vercel Bot temporarily deployed to Preview – beta February 8, 2024 01:47 Inactive
Comment thread packages/react/src/Delay.spec.tsx Outdated
Comment on lines +39 to +43
vi.advanceTimersByTime(ms('0.5s'))

expect(screen.queryByRole('paragraph')).toBeInTheDocument()

vi.advanceTimersByTime(ms('0.5s'))
Copy link
Copy Markdown
Member

@manudeli manudeli Feb 8, 2024

Choose a reason for hiding this comment

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

In my opinion, fallback should be expose immediately

Suggested change
vi.advanceTimersByTime(ms('0.5s'))
expect(screen.queryByRole('paragraph')).toBeInTheDocument()
vi.advanceTimersByTime(ms('0.5s'))
expect(screen.queryByRole('paragraph')).toBeInTheDocument()
vi.advanceTimersByTime(ms('1s'))

Copy link
Copy Markdown
Contributor Author

@ssi02014 ssi02014 Feb 8, 2024

Choose a reason for hiding this comment

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

Fix done!

Additionally, I followed the guidelines in testing-library. The changes are as follows

beforeEach(() => {
  vi.useFakeTimers({ shouldAdvanceTime: true })
})

afterEach(() => {
  vi.runOnlyPendingTimers()
  vi.useRealTimers()
})

Reference

https://testing-library.com/docs/using-fake-timers/

@vercel vercel Bot temporarily deployed to Preview – beta February 8, 2024 02:14 Inactive
@vercel vercel Bot temporarily deployed to Preview – visualization February 8, 2024 02:15 Inactive
@vercel vercel Bot temporarily deployed to Preview – main February 8, 2024 02:17 Inactive
@vercel vercel Bot temporarily deployed to Preview – beta February 8, 2024 02:54 Inactive
@vercel vercel Bot temporarily deployed to Preview – main February 8, 2024 02:56 Inactive
Copy link
Copy Markdown
Member

@manudeli manudeli left a comment

Choose a reason for hiding this comment

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

Thanks! In my opinion, using timeout option of waitFor is optional thing to approve this Pull Request. I think I need to study more about fake timer

@vercel vercel Bot temporarily deployed to Preview – visualization February 8, 2024 02:57 Inactive
@ssi02014
Copy link
Copy Markdown
Contributor Author

ssi02014 commented Feb 8, 2024

@manudeli Thanks! 👍

@manudeli manudeli merged commit d3b7c15 into toss:main Feb 8, 2024
@github-actions github-actions Bot mentioned this pull request Feb 8, 2024
@ssi02014 ssi02014 deleted the react/Delay branch February 8, 2024 06:53
manudeli pushed a commit that referenced this pull request Feb 8, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @suspensive/react@1.26.1

### Patch Changes

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - fix(react): define
default prop of each components

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - test(react): add test
case for fallback prop of Delay

## @suspensive/react-query@1.26.1

### Patch Changes

- Updated dependencies
\[[`d3b7c15`](d3b7c15),
[`d3b7c15`](d3b7c15)]:
    -   @suspensive/react@1.26.1

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
manudeli added a commit that referenced this pull request Aug 3, 2024
…709)

# Overview

I was looking at the `Delay` component in `@suspensive/react` and it
seems that if we utilize the generic type of `PropsWithChildren`, we can
remove the unnecessary `OmitKeyOf` utility type.

```ts
type PropsWithChildren<P = unknown> = P & { children?: ReactNode | undefined };
```

Also, I added test code for the fallback of the Delay component. 

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md)
2. I added documents and tests.

---------

Co-authored-by: Jonghyeon Ko <manudeli.ko@gmail.com>
Co-authored-by: Jonghyeon Ko <jonghyeon.ko@wesang.com>
manudeli added a commit that referenced this pull request Aug 3, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @suspensive/react@1.26.1

### Patch Changes

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - fix(react): define
default prop of each components

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - test(react): add test
case for fallback prop of Delay

## @suspensive/react-query@1.26.1

### Patch Changes

- Updated dependencies
\[[`d3b7c15`](d3b7c15),
[`d3b7c15`](d3b7c15)]:
    -   @suspensive/react@1.26.1

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
manudeli pushed a commit that referenced this pull request Aug 3, 2024
…709)

# Overview

I was looking at the `Delay` component in `@suspensive/react` and it
seems that if we utilize the generic type of `PropsWithChildren`, we can
remove the unnecessary `OmitKeyOf` utility type.

```ts
type PropsWithChildren<P = unknown> = P & { children?: ReactNode | undefined };
```

Also, I added test code for the fallback of the Delay component. 

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md)
2. I added documents and tests.

---------
manudeli added a commit that referenced this pull request Aug 3, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @suspensive/react@1.26.1

### Patch Changes

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - fix(react): define
default prop of each components

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - test(react): add test
case for fallback prop of Delay

## @suspensive/react-query@1.26.1

### Patch Changes

- Updated dependencies
\[[`d3b7c15`](d3b7c15),
[`d3b7c15`](d3b7c15)]:
    -   @suspensive/react@1.26.1
manudeli added a commit that referenced this pull request Aug 3, 2024
…709)

# Overview

I was looking at the `Delay` component in `@suspensive/react` and it
seems that if we utilize the generic type of `PropsWithChildren`, we can
remove the unnecessary `OmitKeyOf` utility type.

```ts
type PropsWithChildren<P = unknown> = P & { children?: ReactNode | undefined };
```

Also, I added test code for the fallback of the Delay component. 

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md)
2. I added documents and tests.

---------

Co-authored-by: Jonghyeon Ko <manudeli.ko@gmail.com>
Co-authored-by: Jonghyeon Ko <jonghyeon.ko@wesang.com>
manudeli added a commit that referenced this pull request Aug 3, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @suspensive/react@1.26.1

### Patch Changes

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - fix(react): define
default prop of each components

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - test(react): add test
case for fallback prop of Delay

## @suspensive/react-query@1.26.1

### Patch Changes

- Updated dependencies
\[[`d3b7c15`](d3b7c15),
[`d3b7c15`](d3b7c15)]:
    -   @suspensive/react@1.26.1
manudeli added a commit that referenced this pull request Aug 3, 2024
…709)

# Overview

I was looking at the `Delay` component in `@suspensive/react` and it
seems that if we utilize the generic type of `PropsWithChildren`, we can
remove the unnecessary `OmitKeyOf` utility type.

```ts
type PropsWithChildren<P = unknown> = P & { children?: ReactNode | undefined };
```

Also, I added test code for the fallback of the Delay component. 

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md)
2. I added documents and tests.

---------

Co-authored-by: Jonghyeon Ko <manudeli.ko@gmail.com>
Co-authored-by: Jonghyeon Ko <jonghyeon.ko@wesang.com>
manudeli added a commit that referenced this pull request Aug 3, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @suspensive/react@1.26.1

### Patch Changes

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - fix(react): define
default prop of each components

- [#709](#709)
[`d3b7c15`](d3b7c15)
Thanks [@ssi02014](https://github.com/ssi02014)! - test(react): add test
case for fallback prop of Delay

## @suspensive/react-query@1.26.1

### Patch Changes

- Updated dependencies
\[[`d3b7c15`](d3b7c15),
[`d3b7c15`](d3b7c15)]:
    -   @suspensive/react@1.26.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants