Skip to content

fix(react): add defineSuspense util function #1065

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

Merged
merged 6 commits into from
Jul 10, 2024

Conversation

ssi02014
Copy link
Contributor

@ssi02014 ssi02014 commented Jul 10, 2024

close: #1058

Overview

Add the defineSuspense utility function discussed in the issue article above, and write the test code.

The reason we defined SuspenseClientOnly within defineSuspense is because we are getting the "dependency cycle detected" issue.

If you have any additional thoughts on the above issues, please let us know!

PR Checklist

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

@ssi02014 ssi02014 requested a review from manudeli as a code owner July 10, 2024 09:53
Copy link

changeset-bot bot commented Jul 10, 2024

🦋 Changeset detected

Latest commit: 2195a58

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

This PR includes changesets to release 4 packages
Name Type
@suspensive/react Patch
@suspensive/react-query-4 Patch
@suspensive/react-query-5 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

Copy link

vercel bot commented Jul 10, 2024

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

Name Status Preview Comments Updated (UTC)
suspensive.org ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 10, 2024 1:29pm
v1.suspensive.org ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 10, 2024 1:29pm
visualization.suspensive.org ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 10, 2024 1:29pm

Copy link

vercel bot commented Jul 10, 2024

@ssi02014 is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codspeed-hq bot commented Jul 10, 2024

CodSpeed Performance Report

Merging #1065 will create unknown performance changes

Comparing ssi02014:feat/defineSuspense (2195a58) with main (df5cedb)

Summary

⚠️ No benchmarks were detected in both the base of the PR and the PR.

@codecov-commenter
Copy link

codecov-commenter commented Jul 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.23%. Comparing base (df5cedb) to head (2195a58).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1065      +/-   ##
==========================================
+ Coverage   84.18%   84.23%   +0.05%     
==========================================
  Files          51       52       +1     
  Lines         550      552       +2     
  Branches      117      117              
==========================================
+ Hits          463      465       +2     
  Misses         82       82              
  Partials        5        5              
Components Coverage Δ
@suspensive/react 97.05% <100.00%> (+0.02%) ⬆️
@suspensive/react-query 75.28% <ø> (ø)
@suspensive/react-query-4 0.00% <ø> (ø)
@suspensive/react-query-5 0.00% <ø> (ø)
@suspensive/jotai 0.00% <ø> (ø)
@suspensive/promise 100.00% <ø> (ø)
@suspensive/react-await 100.00% <ø> (ø)
@suspensive/react-image 80.39% <ø> (ø)

@manudeli manudeli changed the title feat(react): add defineSuspense util function fix(react): add defineSuspense util function Jul 10, 2024
Copy link
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! 🚀🚀🚀

Copy link
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.

@ssi02014 Double check please! I modify your Pull Request

Comment on lines +10 to +47
/* eslint-disable @typescript-eslint/unified-signatures */
export function defineSuspense(options: { componentPropsClientOnly: true }): typeof SuspenseClientOnly
export function defineSuspense(options: { defaultPropsClientOnly: true }): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: true
defaultPropsClientOnly: undefined
}): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: undefined
defaultPropsClientOnly: true
}): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: true
defaultPropsClientOnly: true
}): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: true
defaultPropsClientOnly: false
}): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: false
defaultPropsClientOnly: true
}): typeof SuspenseClientOnly
export function defineSuspense(options: {
componentPropsClientOnly: false
defaultPropsClientOnly: false
}): typeof Suspense
// eslint-disable-next-line @typescript-eslint/ban-types
export function defineSuspense(options: {}): typeof Suspense
export function defineSuspense({
defaultPropsClientOnly,
componentPropsClientOnly,
}: {
defaultPropsClientOnly?: boolean
componentPropsClientOnly?: boolean
}): typeof SuspenseClientOnly | typeof Suspense {
return componentPropsClientOnly ?? defaultPropsClientOnly ? SuspenseClientOnly : Suspense
}
Copy link
Member

Choose a reason for hiding this comment

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

I added function overriding.

Comment on lines +4 to +30
describe('defineSuspense', () => {
it('type check', () => {
expectTypeOf(defineSuspense({ componentPropsClientOnly: true })).toEqualTypeOf<typeof SuspenseClientOnly>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: true })).toEqualTypeOf<typeof SuspenseClientOnly>()
expectTypeOf(defineSuspense({ componentPropsClientOnly: true, defaultPropsClientOnly: undefined })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ componentPropsClientOnly: undefined, defaultPropsClientOnly: true })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: true, componentPropsClientOnly: true })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: true, componentPropsClientOnly: false })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: false, componentPropsClientOnly: true })).toEqualTypeOf<
typeof SuspenseClientOnly
>()
expectTypeOf(defineSuspense({ defaultPropsClientOnly: false, componentPropsClientOnly: false })).toEqualTypeOf<
typeof Suspense
>()
expectTypeOf(
defineSuspense({ defaultPropsClientOnly: undefined, componentPropsClientOnly: undefined })
).toEqualTypeOf<typeof Suspense>()
})
})
Copy link
Member

Choose a reason for hiding this comment

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

I added type test codes

Comment on lines +6 to +16
expect(defineSuspense({ componentPropsClientOnly: true })).toBe(SuspenseClientOnly)
expect(defineSuspense({ componentPropsClientOnly: true, defaultPropsClientOnly: undefined })).toBe(
SuspenseClientOnly
)
})
it('should return SuspenseClientOnly when defaultPropsClientOnly is true and componentPropsClientOnly is undefined', () => {
expect(defineSuspense({ defaultPropsClientOnly: true })).toBe(SuspenseClientOnly)
expect(defineSuspense({ componentPropsClientOnly: undefined, defaultPropsClientOnly: true })).toBe(
SuspenseClientOnly
)
})
Copy link
Member

Choose a reason for hiding this comment

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

I added more test code

@ssi02014
Copy link
Contributor Author

@manudeli Thank you for improving this task👍 I've checked it out.

@manudeli manudeli merged commit 2216377 into toss:main Jul 10, 2024
14 checks passed
@ssi02014 ssi02014 deleted the feat/defineSuspense branch July 10, 2024 14:06
manudeli pushed a commit that referenced this pull request Jul 10, 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@2.6.1

### Patch Changes

- [#1065](#1065)
[`2216377`](2216377)
Thanks [@ssi02014](https://github.com/ssi02014)! - feat(react): fix
clientOnly prop of Suspense with defaultProps

## @suspensive/react-query@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1
    -   @suspensive/react-query-4@2.6.1
    -   @suspensive/react-query-5@2.6.1

## @suspensive/react-query-4@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1

## @suspensive/react-query-5@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.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
close: #1058

# Overview
Add the `defineSuspense` utility function discussed in the issue article
above, and write the test code.

The reason we defined `SuspenseClientOnly` within `defineSuspense` is
because we are getting the `"dependency cycle detected"` issue.

If you have any additional thoughts on the above issues, please let us
know!

## PR Checklist

- [x] I did below actions if need

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

---------

Co-authored-by: Jonghyeon Ko <jonghyeon@toss.im>
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@2.6.1

### Patch Changes

- [#1065](#1065)
[`2216377`](2216377)
Thanks [@ssi02014](https://github.com/ssi02014)! - feat(react): fix
clientOnly prop of Suspense with defaultProps

## @suspensive/react-query@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1
    -   @suspensive/react-query-4@2.6.1
    -   @suspensive/react-query-5@2.6.1

## @suspensive/react-query-4@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1

## @suspensive/react-query-5@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.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
close: #1058

# Overview
Add the `defineSuspense` utility function discussed in the issue article
above, and write the test code.

The reason we defined `SuspenseClientOnly` within `defineSuspense` is
because we are getting the `"dependency cycle detected"` issue.

If you have any additional thoughts on the above issues, please let us
know!

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/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@2.6.1

### Patch Changes

- [#1065](#1065)
[`2216377`](2216377)
Thanks [@ssi02014](https://github.com/ssi02014)! - feat(react): fix
clientOnly prop of Suspense with defaultProps

## @suspensive/react-query@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1
    -   @suspensive/react-query-4@2.6.1
    -   @suspensive/react-query-5@2.6.1

## @suspensive/react-query-4@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1

## @suspensive/react-query-5@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1
manudeli added a commit that referenced this pull request Aug 3, 2024
close: #1058

# Overview
Add the `defineSuspense` utility function discussed in the issue article
above, and write the test code.

The reason we defined `SuspenseClientOnly` within `defineSuspense` is
because we are getting the `"dependency cycle detected"` issue.

If you have any additional thoughts on the above issues, please let us
know!

## PR Checklist

- [x] I did below actions if need

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

---------

Co-authored-by: Jonghyeon Ko <jonghyeon@toss.im>
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@2.6.1

### Patch Changes

- [#1065](#1065)
[`2216377`](2216377)
Thanks [@ssi02014](https://github.com/ssi02014)! - feat(react): fix
clientOnly prop of Suspense with defaultProps

## @suspensive/react-query@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1
    -   @suspensive/react-query-4@2.6.1
    -   @suspensive/react-query-5@2.6.1

## @suspensive/react-query-4@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1

## @suspensive/react-query-5@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1
manudeli added a commit that referenced this pull request Aug 3, 2024
close: #1058

# Overview
Add the `defineSuspense` utility function discussed in the issue article
above, and write the test code.

The reason we defined `SuspenseClientOnly` within `defineSuspense` is
because we are getting the `"dependency cycle detected"` issue.

If you have any additional thoughts on the above issues, please let us
know!

## PR Checklist

- [x] I did below actions if need

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

---------

Co-authored-by: Jonghyeon Ko <jonghyeon@toss.im>
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@2.6.1

### Patch Changes

- [#1065](#1065)
[`2216377`](2216377)
Thanks [@ssi02014](https://github.com/ssi02014)! - feat(react): fix
clientOnly prop of Suspense with defaultProps

## @suspensive/react-query@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1
    -   @suspensive/react-query-4@2.6.1
    -   @suspensive/react-query-5@2.6.1

## @suspensive/react-query-4@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.1

## @suspensive/react-query-5@2.6.1

### Patch Changes

- Updated dependencies
\[[`2216377`](2216377)]:
    -   @suspensive/react@2.6.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.

[Question]: Suspense's DefinedSuspense
3 participants