You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importReact,{useEffect}from"preact/compat";importReactDOMfrom"preact/compat";/*/import React, { useEffect } from "react";import ReactDOM from "react-dom";*/functionuseTest(){try{let[,dispatch]=React.useReducer(()=>{thrownewError("X");},"a");return{load(){dispatch("b");}};}catch(e){console.log("useReducer",e.message);throwe;}}functionTest(){let{ load }=useTest();useEffect(()=>{try{load();}catch(e){console.log("dispatch",e.message);throwe;}});return"Test";}classCatcherextendsReact.Component{constructor(){super();this.state={error: null};}componentDidCatch(error){this.setState({error: error.message});}render(){if(this.state.error){return<p>Something went badly wrong: {this.state.error}</p>;}returnthis.props.children;}}functionApp(){return(<Catcher><Test/></Catcher>);}ReactDOM.render(<App/>,document.getElementById("root"));
Steps to reproduce
Open reproduction
Expected Behavior
🤷♂️ (not sure how far you want to take the "1:1" compatibility to React 😄 )
Actual Behavior
An error is thrown in the reducer function.
Preact throws this error back through the the dispatch() call (so load() in this case). ("dispatch" is logged).
React throws this error back "through the the useReduce() call". ("useReducer" is logged).
Context
This messes with @testing-library/preact-hooks-testing-library because you need to catch the actual calls and can't rely on result.error. testing-library/preact-hooks-testing-library#3
The text was updated successfully, but these errors were encountered:
This could be a very minor addition to hooks/index.js that wouldn't make a huge difference but improve consistency as well.
Edit: Just editing to state that I'm wrong; this could be more tricky, since state changes like these would also still have to be aborted if the state remains the same. React does this by marking the current fiber as potentially unchanged. In Preact this may not be possible as the render phase has already begun and can't be interrupted as it's not split into two phases as far as I'm aware.
Reproduction
https://codesandbox.io/s/preact-usereducer-error-lr1mx?file=/src/index.js
Steps to reproduce
Open reproduction
Expected Behavior
🤷♂️ (not sure how far you want to take the "1:1" compatibility to React 😄 )
Actual Behavior
An error is thrown in the reducer function.
Preact throws this error back through the the dispatch() call (so
load()
in this case). ("dispatch" is logged).React throws this error back "through the the useReduce() call". ("useReducer" is logged).
Context
This messes with
@testing-library/preact-hooks-testing-library
because you need to catch the actual calls and can't rely onresult.error
. testing-library/preact-hooks-testing-library#3The text was updated successfully, but these errors were encountered: