Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/prevent-recursiv…
Browse files Browse the repository at this point in the history
…e-fallback-throw-error
  • Loading branch information
manudeli committed Jan 20, 2025
2 parents 87014d3 + c0c9c34 commit 95b27ec
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 17 deletions.
2 changes: 2 additions & 0 deletions packages/jotai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @suspensive/jotai

## 2.18.12

## 2.18.11

## 2.18.10
Expand Down
2 changes: 1 addition & 1 deletion packages/jotai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@suspensive/jotai",
"version": "2.18.11",
"version": "2.18.12",
"description": "Suspensive interfaces for jotai",
"keywords": [
"suspensive",
Expand Down
7 changes: 7 additions & 0 deletions packages/react-query-4/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @suspensive/react-query-4

## 2.18.12

### Patch Changes

- Updated dependencies [[`421d49d`](https://github.com/toss/suspensive/commit/421d49d6282bd375772aa898bca7b3f88b6a7ad8)]:
- @suspensive/react@2.18.12

## 2.18.11

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/react-query-4/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@suspensive/react-query-4",
"version": "2.18.11",
"version": "2.18.12",
"description": "Suspensive interfaces for @tanstack/react-query@4",
"keywords": [
"suspensive",
Expand Down Expand Up @@ -59,7 +59,7 @@
"react": "catalog:react19"
},
"peerDependencies": {
"@suspensive/react": "workspace:^2.18.11",
"@suspensive/react": "workspace:^2.18.12",
"@tanstack/react-query": "^4",
"react": "^18 || ^19"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/react-query-5/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @suspensive/react-query-5

## 2.18.12

### Patch Changes

- Updated dependencies [[`421d49d`](https://github.com/toss/suspensive/commit/421d49d6282bd375772aa898bca7b3f88b6a7ad8)]:
- @suspensive/react@2.18.12

## 2.18.11

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/react-query-5/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@suspensive/react-query-5",
"version": "2.18.11",
"version": "2.18.12",
"description": "Suspensive interfaces for @tanstack/react-query@5",
"keywords": [
"suspensive",
Expand Down Expand Up @@ -59,7 +59,7 @@
"react": "catalog:react19"
},
"peerDependencies": {
"@suspensive/react": "workspace:^2.18.11",
"@suspensive/react": "workspace:^2.18.12",
"@tanstack/react-query": "^5",
"react": "^18 || ^19"
},
Expand Down
9 changes: 9 additions & 0 deletions packages/react-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @suspensive/react-query

## 2.18.12

### Patch Changes

- Updated dependencies [[`421d49d`](https://github.com/toss/suspensive/commit/421d49d6282bd375772aa898bca7b3f88b6a7ad8)]:
- @suspensive/react@2.18.12
- @suspensive/react-query-4@2.18.12
- @suspensive/react-query-5@2.18.12

## 2.18.11

### Patch Changes
Expand Down
8 changes: 4 additions & 4 deletions packages/react-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@suspensive/react-query",
"version": "2.18.11",
"version": "2.18.12",
"description": "Suspensive interfaces for @tanstack/react-query",
"keywords": [
"suspensive",
Expand Down Expand Up @@ -56,8 +56,8 @@
},
"dependencies": {
"@commander-js/extra-typings": "^12.1.0",
"@suspensive/react-query-4": "workspace:^2.18.11",
"@suspensive/react-query-5": "workspace:^2.18.11",
"@suspensive/react-query-4": "workspace:^2.18.12",
"@suspensive/react-query-5": "workspace:^2.18.12",
"cli-table3": "^0.6.5",
"commander": "^12.1.0"
},
Expand All @@ -70,7 +70,7 @@
"react": "catalog:react19"
},
"peerDependencies": {
"@suspensive/react": "workspace:^2.18.11",
"@suspensive/react": "workspace:^2.18.12",
"@tanstack/react-query": "^4 || ^5",
"react": "^18 || ^19"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @suspensive/react

## 2.18.12

### Patch Changes

- [#1414](https://github.com/toss/suspensive/pull/1414) [`421d49d`](https://github.com/toss/suspensive/commit/421d49d6282bd375772aa898bca7b3f88b6a7ad8) Thanks [@manudeli](https://github.com/manudeli)! - fix(react): re-throw SuspensiveError before rerender

## 2.18.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@suspensive/react",
"version": "2.18.11",
"version": "2.18.12",
"description": "Suspensive interface for react",
"keywords": [
"suspensive",
Expand Down
26 changes: 24 additions & 2 deletions packages/react/src/ErrorBoundary.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,14 @@ describe('useErrorBoundary', () => {
</ErrorBoundary>
).getByText(TEXT)
).toBeInTheDocument()
expect(() =>
render(
createElement(() => {
useErrorBoundary()
return <></>
})
)
).toThrow(SuspensiveError)
expect(() =>
render(
<ErrorBoundary
Expand Down Expand Up @@ -472,16 +480,23 @@ describe('useErrorBoundaryFallbackProps', () => {
})

it('should guarantee hook calling position is in fallback of ErrorBoundary', () => {
const inFallback = vi.fn()
expect(() =>
render(
<ErrorBoundary fallback={(props) => <>{props.error.message}</>}>
<ErrorBoundary
fallback={(props) => {
inFallback()
return <>{props.error.message}</>
}}
>
{createElement(() => {
useErrorBoundaryFallbackProps()
return <></>
})}
</ErrorBoundary>
)
).toThrow(SuspensiveError)
expect(inFallback).toHaveBeenCalledTimes(0)
})
it('should be prevented to be called outside fallback of ErrorBoundary', () => {
expect(() =>
Expand All @@ -494,15 +509,22 @@ describe('useErrorBoundaryFallbackProps', () => {
).toThrow(SuspensiveError)
})
it("should be prevented to be called in children of ErrorBoundary (ErrorBoundary shouldn't catch SuspensiveError)", () => {
const inFallback = vi.fn()
expect(() =>
render(
<ErrorBoundary fallback={(props) => <>{props.error.message}</>}>
<ErrorBoundary
fallback={(props) => {
inFallback()
return <>{props.error.message}</>
}}
>
{createElement(() => {
useErrorBoundaryFallbackProps()
return <></>
})}
</ErrorBoundary>
)
).toThrow(SuspensiveError)
expect(inFallback).toHaveBeenCalledTimes(0)
})
})
6 changes: 3 additions & 3 deletions packages/react/src/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ class BaseErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState
}

componentDidCatch(error: Error, info: ErrorInfo) {
if (error instanceof SuspensiveError) {
throw error
}
this.props.onError?.(error, info)
}

Expand All @@ -133,6 +130,9 @@ class BaseErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState
let childrenOrFallback = children

if (isError) {
if (error instanceof SuspensiveError) {
throw error
}
if (error instanceof ErrorInFallback) {
throw error.originalError
}
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 95b27ec

Please sign in to comment.