mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
fix(core/bind): avoid triggering SUSPENSE when the stream emits synchronously
This commit is contained in:
parent
fcd6641b14
commit
14398b3509
@ -5,7 +5,7 @@ import {
|
||||
screen,
|
||||
} from "@testing-library/react"
|
||||
import { act, renderHook } from "@testing-library/react-hooks"
|
||||
import React, { Suspense, useEffect, FC } from "react"
|
||||
import React, { Suspense, useEffect, FC, StrictMode } from "react"
|
||||
import {
|
||||
BehaviorSubject,
|
||||
defer,
|
||||
@ -15,6 +15,7 @@ import {
|
||||
throwError,
|
||||
Observable,
|
||||
merge,
|
||||
NEVER,
|
||||
} from "rxjs"
|
||||
import {
|
||||
delay,
|
||||
@ -491,4 +492,20 @@ describe("connectObservable", () => {
|
||||
|
||||
expect(errorCallback).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("should not trigger suspense when the stream emits synchronously", () => {
|
||||
const [useValue] = bind(NEVER.pipe(startWith("Hello")))
|
||||
|
||||
const Component: FC = () => <>{useValue()}</>
|
||||
render(
|
||||
<StrictMode>
|
||||
<Suspense fallback={<div>Loading...</div>}>
|
||||
<Component />
|
||||
</Suspense>
|
||||
</StrictMode>,
|
||||
)
|
||||
|
||||
expect(screen.queryByText("Loading...")).toBeNull()
|
||||
expect(screen.queryByText("Hello")).not.toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@ -49,7 +49,10 @@ const reactEnhancer = <T>(source$: BehaviorObservable<T>): (() => T) => {
|
||||
promise = undefined
|
||||
})
|
||||
|
||||
if (value !== EMPTY_VALUE) return value
|
||||
if (value !== EMPTY_VALUE) {
|
||||
promise = undefined
|
||||
return value
|
||||
}
|
||||
|
||||
throw error !== EMPTY_VALUE ? error : promise
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user