-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(react): define default prop of each components(Delay, Suspense) #709
Conversation
🦋 Changeset detectedLatest commit: b9348bf The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
✅ Deploy Preview for suspensive-org ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for suspensive-next-streaming-react-query ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov Report
Additional details and impacted files@@ 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
|
@@ -2,8 +2,9 @@ import { createContext } from 'react' | |||
import type { DelayProps, SuspenseProps } from '..' | |||
import type { OmitKeyOf } from '../utility-types' | |||
|
|||
export const DelayDefaultPropsContext = createContext<OmitKeyOf<DelayProps, 'children'>>({ | |||
export const DelayDefaultPropsContext = createContext<DelayProps>({ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🙏
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>
|
||
vi.advanceTimersByTime(ms('0.5s')) | ||
|
||
await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument()) |
There was a problem hiding this comment.
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?
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
There was a problem hiding this comment.
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
})
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.
There was a problem hiding this comment.
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) 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/react/src/Delay.spec.tsx
Outdated
vi.advanceTimersByTime(ms('0.5s')) | ||
|
||
expect(screen.queryByRole('paragraph')).toBeInTheDocument() | ||
|
||
vi.advanceTimersByTime(ms('0.5s')) |
There was a problem hiding this comment.
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
vi.advanceTimersByTime(ms('0.5s')) | |
expect(screen.queryByRole('paragraph')).toBeInTheDocument() | |
vi.advanceTimersByTime(ms('0.5s')) | |
expect(screen.queryByRole('paragraph')).toBeInTheDocument() | |
vi.advanceTimersByTime(ms('1s')) |
There was a problem hiding this comment.
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
There was a problem hiding this 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
@manudeli Thanks! 👍 |
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>
…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>
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>
…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. ---------
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
…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>
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
…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>
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
Overview
I was looking at the
Delay
component in@suspensive/react
and it seems that if we utilize the generic type ofPropsWithChildren
, we can remove the unnecessaryOmitKeyOf
utility type.Also, I added test code for the fallback of the Delay component.
PR Checklist