-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
chore(tests): remove imperfectly working test added in #276 #1184
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 2719b35:
|
That test was added in some PR to catch some bugs.
Maybe we should just leave it? Or, would you like to investigate (1)? |
Oh, I see. it('re-renders with useLayoutEffect', async () => {
const useBoundStore = create(() => ({ state: false }))
function Component() {
const { state } = useBoundStore()
useLayoutEffect(() => {
useBoundStore.setState({ state: true })
}, [])
return <>{`${state}`}</>
}
const container = document.createElement('div')
await actAndAssertBasedOnReactVersion(container, <Component />, () => {
expect(container.innerHTML).toBe('true')
})
})
async function actAndAssertBasedOnReactVersion(
container: Element | DocumentFragment,
componentToRender: JSX.Element,
expectCallback: () => void
) {
let root: Root
const isReactPost18 = parseInt(React.version) > 17
if (isReactPost18) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createRoot } = require('react-dom/client')
root = createRoot(container)
}
isReactPost18
? act(() => root.render(componentToRender))
: ReactDOM.render(componentToRender, container)
await waitFor(expectCallback)
isReactPost18
? act(() => root.unmount())
: ReactDOM.unmountComponentAtNode(container)
} I think it should solve it for all tests but I am not sure whether it is the best approach. Also needs |
Well, I think we could just skip the test for react 18... Would you please have a look at #280 and see why we have this test? Anyway, I think it's better to hide warning instead of using const consoleError = console.error
beforeEach(() => {
console.error = jest.fn((message) => {
if (
message.startsWith('Warning: ReactDOM.render is no longer supported')
) {
return
}
consoleError(message)
})
})
afterEach(() => {
console.error = consoleError
}) |
Hmm. It looks like the test is useless. In pre 3.3.1 was a problem with useEffect (https://codesandbox.io/s/zen-goldstine-1571u4 - flickering screen red/green). @leobastiani changed it to useIsoLayoutEffect. I don't see this code in version 4 anymore but it looks like the bug reappeared. Anyway, the test doesn't catch this bug, I removed it. |
c1e1f73
to
2719b35
Compare
What does this mean? I think we still use |
Look at the linked codesandbox. The background blinks to red only on versions pre 3.3.1 and post 4-alpha. Eg. switch zustand's version to 3.1.4 (red blink), then 3.3.2 (no blink) and then 4.0 (red blink). I think it is the same bug that was reported in #276 Edit: IMO we can close this PR without removing this test and without disabling console.error. I agree that it is reasonable to have both. |
Oh, I see. So, the #276 behavior is reproduced with zustand v4.0.0 and react 17, but the test doesn't catch it. Do you happen to know how to fix this?? This is probably an intentional behavior or a bug in use-sync-external-store/shim. We could report an issue in the react repo. I'm actually fine to remove the test if it's an intentional behavior or in any case. A side note: in your codesandbox, you use a boolean value as a store. #1144 might be of your interest. |
Unfortunately not. Maybe @leobastiani will know because he fixed it before. I will need to dig into it more, but I don't have time currently.
Ok, so I will not revert the last commit.
It's not my code, I copied URL to it from #276 but GTK (+1) |
Merging this because I think as follows:
|
Fixed console error about React 17 -> 18 in
basic.test.tsx