repository
stringclasses
156 values
issue title
stringlengths
1
1.01k
labels
stringclasses
8 values
body
stringlengths
1
270k
facebookreact
eslint plugin react hook bug react hook xxx be call in function child
Question
bug what be the current behavior the hook create in child function provide in defaultprop populate error react hook rule of hook js const app prop prop child prop app defaultprop child prop const count setcount usestate 0 return count count setcount count 1 increment react hook usestate be call in function child which be neither a react function component or a custom react hook function react hook rule of hook what be the expect behavior hook inside child function in defaultprop should not create an error when hook be use which version of react and which browser os be affect by this issue do this work in previous version of react same as in the codesandbox dependency react 16 8 6 react dom 16 8 6 react script 3 0 0
facebookreact
declarative vs imperative code style use hook
Question
if this should be ask on stack overflow instead please let I know and feel free to close the issue consider a component that fetch some datum in a custom hook save the fetched datum in a state hook and notify the user that datum have be fetch use a prop callback notify the user can be do imperatively js function component prop const datum setdata usestate null useapi api datum then setdata then prop onfetche return datatoelement datum or declaratively use an effect hook js function component prop const datum setdata usestate null useapi api datum then setdata useeffect if datum prop onfetche datum return datatoelement datum react seem to promote a declarative approach but what I ve find be that when component grow large and complex use declarative effect hook make the flow of datum and action quite hard to follow if you re not careful a lot of thing start to depend on a lot of other thing and the predict result become non intuitive and hard to wrap your head around I would like to know other people opinion on this matter and whether or not an imperative approach might sometimes be well
facebookreact
an error in render boundary behave unexpectedly on reactdom hydrate
Bug
from the react org doc error boundary preserve the declarative nature of react somewhere deep in the tree it will still correctly propagate to the close error boundary do you want to request a feature or report a bug I be not sure if this be a bug or intend behavior because it only happen with reactdom hydrate when an error be throw only within render what be the current behavior if an error be throw in the render method of any component the error boundary at any give top level render its fallback exactly where that component be instead of where the error boundary be define if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below what be the expect behavior just like it reactdom hydrate behave if the error happen in componentdidmount the error boundary s fallback should be render where the error boundary element be actually declare which version of react and which browser os be affect by this issue do this work in previous version of react v16 8 6 on chrome haven t test previous version but I think to remember this work correctly when we upgrade to v16 and add our top level page boundary
facebookreact
why useffect run return at frist
Question
jsx export const useconfigstatehook const visible setvisible usestate hide const cofigvisible setcofigvisible usestate false const card setcard usestate useeffect eventproxy on setconfigbtn value setvisible value eventproxy on setconfigopen value setcofigvisible value false cofigvisible eventproxy on setcard card const ichart prop card if ichart return setcard setcard e eventproxy trigger chartref e e settimeout eventproxy trigger setconfigview e renderconfig 200 prop return eventproxy off setcard eventproxy off setconfigbtn eventproxy off setconfigopen eventproxy off setconfigview return visible cofigvisible card
facebookreact
how to test multiple state change with act
Question
do you want to request a feature or report a bug bug what be the current behavior with the new act function I m unsure how to test state transition that occur during an event handler process for example if I have this handler that be call on form submission const issubmitte setissubmitte usestate false const handlesubmit async setissubmitte true await fetcher setissubmitte false then I want to be able to test that issubmitte state be indeed set to true before fetcher be call due to the nature of act I believe it defer all state change until after its provide function have be run I m not sure that this be currently possible previously I ve be test use await new promise settimeout to flush the current runtime task queue which work fine for this use case I have find a way to make this work without trigger the act warning but it feel like a hack I have to wrap act around my expectation not the submit it display indicator when form be submit async reacttestutil simulate submit form await act async expect container queryselector submittingindicator not tobenull I ve provide this test in a repo together with a couple of other test which complete the feature see the link below if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below what be the expect behavior there s a way for I to test this which doesn t feel like a hack which version of react and which browser os be affect by this issue do this work in previous version of react 16 9 0 alpha 0
facebookreact
usememo in strictmode
Enhancement
do you want to request a feature or report a bug feature what be the current behavior write your code so that it still work without usememo usememo I can try write my code with this in mind but it would be very helpful if react could try to help spot issue what be the expect behavior strictmode can already help we detect side effect in render by call it twice it also help detect side effect in usememo by call it twice if the dependency change however there s no way to simulate a purge of the cache it might help call the factory in strictmode regardless of the dependency or only on the second render other approach like would give more control to the user there s already a working solution by use some feature flag at build time e g react usememo factory strict undefined dependency but the linter can t work with that use react usememo factory dependency purge memo cache current would make it more controllable if we write e g test instruction but the linter complain about those too I don t think we have a way to detect if react be between two render call so that we can purge the cache by flip purge memo cache current this be also somewhat opposite to 15278 because we want an api to opt in to cache purge which version of react and which browser os be affect by this issue do this work in previous version of react future version of react that might forget the dependency
facebookreact
use app shell architecture throw warn expect server html to contain a matching in
Question
I be currently use workbox along with webpack the app shell url be app shell I try follow 2 approach 1 in server js I create a dedicated route to handle app shell url javascript server get app shell request response response set content type text html response write 2 second approach I create a route app shell which correspond to an element with content loading javascript const appshellcomponent react fc jsx element loading in both case I get the above mismatch warn if I make appshellcomponent exactly same as homecomponent I e path then the error go away if the app be invoke from the home page path I e however if any other route be invoke the warning come back again please suggest a well approach thank
facebookreact
question about owner alternate
Question
it seem that in react 16 every react element child contain cyclic property owner alternate alternate alternate alternate image so it be easy to cause maximum call stack exceed error when developer compare prop child in deep way like deep equal this cause bug for community library like react helmet I be extremely curious about why react have owner alternate and what it stand for as it be name as owner could it be well if we make owner not enumerable I try to search source code and but still can t find any clue thank in advance
facebookreact
not wrap in act warning trigger by an async change in useeffect not sure how to fix
Duplicate
do you want to request a feature or report a bug not really either perhaps just an issue with the act design what be the current behavior I receive the warning an update to inside a test be not wrap in act warn if a component under test have a useeffect that make a change to itself async I assume because the component update itself after the act block if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below I think I ve distil this as far as I can javascript this be the component under test function testcomponent const initialize setinitialize react usestate false this function would really be a jest mock fn of an async http request just put it here to simplify the test const loaddata return new promise resolve resolve react useeffect initialize async function initialize await loaddata setinitialize true this change seem to trigger the act warning but I can t wrap it in an act return initialize load loading and this be the test for the above component beforeeach container document createelement div document body appendchild container aftereach document body removechild container container null test act work in this case act reactdom render container what be the expect behavior the render be happen within the act but I m assume the setinitialize be probably be fire async after the act exit I m not entirely sure how to handle this case since I can t put an act inside the component be test any recommendation or guidance would be much appreciate which version of react and which browser os be affect by this issue do this work in previous version of react react 16 8 6 react dom 16 8 6 jest 24 7 1
facebookreact
testutil renderintodocument return null when valid functional component pass
Question
do you want to request a feature or report a bug I want to report a bug what be the current behavior currently when valid functional component be pass to testutil renderintodocument it return a null and raise no error demo this behavior be reproduce in a sandbox check the console to see testutil renderintodocument output of prepared sample component workaround workaround that satisfy both sfc and fc be wrap component into container const fccounter const count setcount usestate 0 return count setcount count 1 1 testutil renderintodocument what be the expect behavior to render a functional component in bad case provide an error which version of react be affect by this issue react version 16 8 6
facebookreact
usestate cause child to re mount
Question
bug what be the current behavior I have a hook that be suppose to call a callback after a settimeout when I render a list of child with this hook the callback behave differently when its in a function component with usestate than it do if its in a class component to see this in action checkout the codesandbox below the demo should show child component be add to the page and then after 2 second the child be mount it should be remove both the example use the same child component only difference be the parent component be a class vs functional component codesandbox what be the expect behavior the function component should behave like the class component which version of react and which browser os be affect by this issue do this work in previous version of react react v16 8 6 late chrome unsure if this work with previous version of hook
facebookreact
react reconciler typeerror appendallchildren be not a function
Bug
do you want to request a feature or report a bug bug what be the current behavior crash on reconciler unbatchedupdate reconciler updatecontainer this prop child this rootnode this with typeerror appendallchildren be not a function if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below this have occur while update to latest react and reconciler version what be the expect behavior do not crash or give helpful error message which version of react and which browser os be affect by this issue do this work in previous version of react yarn list v1 15 2 warning filtering by argument be deprecate please use the pattern option instead do in 0 85s kev macbook pro react regl test kevzettler yarn list react reconciler yarn list v1 15 2 warning filtering by argument be deprecate please use the pattern option instead
facebookreact
react hook a few inconvenience
Question
1 when use useeffect can not get late state for example I add a event listener in componentdidmount const app const state1 setstate1 usestate state1 const state2 setstate2 usestate state2 useeffect function handler can t get the late state1 and state2 because of the scope document addeventlistener click handler return document removeeventlistener click handler I have to change code into this const app const state1 setstate1 usestate state1 const state2 setstate2 usestate state2 useeffect function handler for the reason of scope can t get the late state1 and state2 document addeventlistener click handler return document removeeventlistener click handler state1 state2 problem solve but the effect execute again wasteful 2 functional prop cause update subcomponent every time const app const state usestate usestate 0 function handlechange do something return in this case subcomponent will update every time app rerender because the onchange prop be change if we need to use state or prop in handlechange we have nothing to do with it if we usecallback see no 1 the last state issue
facebookreact
onanimationend ontransitionend issue
Question
do you want to request a feature or report a bug bug what be the current behavior onanimationend create unexpected behavior in the following example I be create a simple notification component from an array each element in the array be use to generate a html element with a class that have a css animation on it the generate div have an onanimationend binding which will remove they from the array of notification the basic idea be that the notification will fade away use a css animation and then be remove from the array or alternatively I be also allow the user to manually click on the notification element to remove it the interesting bug be as follow if you add two notification the first one will trigger its onanimationend and remove itself the remain notification will suddenly jump to the end of its css animation and never trigger its own onanimationend even more curiously if you add four notification exactly two of they will have the above bug while the other two function properly in fact exactly half of the add element will trigger onanimationend properly while the other half will not the onclick functionality to remove the notification from the array do not cause any unexpected behavior and thus I be force to conclude that the fault lie with onanimationend since they both run the exact same function if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below click the add notification button then press it again before the first element have fade 7 second you will notice that the second notification element get fast forwarded to the end of its animation when the first notification be remove by its onanimationend trigger the second notification will then be stick there never trigger its own onanimationend what be the expect behavior onanimationend should trigger for each element in the loop properly which version of react and which browser os be affect by this issue do this work in previous version of react current version of 16 8 6 display this behavior
facebookreact
use testrenderer act should not silence the reactdom warning
Enhancement
reacttestrenderer act only work for react test renderer reacttestutil act only work for react dom unfortunately due to poor naming people confuse those two thing we need to make sure reacttestrenderer act around react dom update doesn t silence the warning and vice versa currently it do but you can fix it by use an empty object that s unique per renderer instead of a true value add a special warning message when a different renderer be act update that warn message should suggest that you re suppose to use act correspond to the renderer you re use e g react dom test util for react dom this should fix most case where people wrap update in the wrong act
facebookreact
hook for forwardref
Question
do you want to request a feature or report a bug feature what be the current behavior today we use forwardref as a hoc around functional component like this js const mycomponent react forwardref prop ref return some text mycomponent displayname mycomponent what be the expect behavior be it possible to use hook to forward ref for example something like this js const mycomponent prop will return ref that be pass from parent component const forwardedref useforwardredref return some text with this approach we don t need to manually set displayname all the time also this would be great for library as you still export same component not a forwardref hoc which version of react and which browser os be affect by this issue do this work in previous version of react react 16 8 and upper
facebookreact
useeffect how to solve conditional page list
Question
do you want to request a feature or report a bug bug what be the current behavior useeffect how to solve conditional page list 1 reset the page number to 1 when the condition change image 2 request to return the current page and keep the current state image if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below what be the expect behavior properly handle page and condition which version of react and which browser os be affect by this issue do this work in previous version of react 16 8 previously treat in class form
facebookreact
renderwithhook may initialize workinprogresshook at the beginning
Bug
do you want to request a feature or report a bug bug what be the current behavior example here base on issue 15219 I find the reason of this issue be that when errorthrower throw renderwithhook just break down and keep workinprogresshook stay usememo because of the componentdidcatch in errorhandler we can go on the render phase but when we reach the statefulcomponent we get usememo as workinprogresshook and it make statefulcomponent with first hook usememo I guess we can fix this just set workinprogresshook to null at the beginning of renderwithhook I post this issue because I see this comment in renderwithhook base on this example all this variable may also not be reset when start renderwithhook so maybe it s well to put they back js the follow should have already be reset currenthook null workinprogresshook null remainingexpirationtime nowork componentupdatequeue null didschedulerenderphaseupdate false renderphaseupdate null numberofrerender 0 sideeffecttag 0 if no other concern about this I just want to put they back to fix this issue
facebookreact
useeffect fire in child before parent
Question
do you want to request a feature or report a bug feature I believe what be the current behavior right now the effect in useeffect fire child first I know this make sense since the behaviour of the first render have a close correlation to cdm however I can not seem to find a way to fire event parent first before I could do it with cwm and after that be deprecate in the constructor how can I accomplish that with hook codesandbox example what be the use case imagine I want to post to an external server when two component be first render to measure a sort of meaningful paint component a post first render component a component b post first render component b how could I accomplish this with hook
facebookreact
customize display name of custom hook
Enhancement
do you want to request a feature or report a bug feature what be the current behavior for toolchain language that munge the name of function the display of custom hook in react devtool be unreadable for instance in clojurescript we might have a custom hook name window that would be compile into the name my app hook lt window what be the expect desire behavior to have the ability to set a displayname like value on a custom hook to customize it s name in react devtool a potential solution javascript function usesomereallylongnamethatidontwanttoshow implement my custom hook usesomereallylongnamethatidontwanttoshow debugname useshortname useshortname would show up in react devtool instead of usesomereallylongnamethatidontwanttoshow which version of react and which browser os be affect by this issue do this work in previous version of react react 16 8 chrome macos 10 13 6
facebookreact
mimic componentdidmount but with hook
Question
we be try to use hook and we want to mimic componentdidmount but our eslint be respond with react hook react useeffect have a miss dependency checkuser either include it or remove the dependency array react hook exhaustive dep if we add checkuser to the dependency in the useeffect we get the checkuser function make the dependency of useeffect hook change on every render move it inside the useeffect callback alternatively wrap the checkuser definition into its own usecallback hook react hook exhaustive dep if we change the checkuser to use usecallback eslint be respond with react hook react usecallback have a miss dependency handleuserstate either include it or remove the dependency array react hook exhaustive dep what be the correct way to solve this or should we ignore the warning javascript function handleuserstate respon some code function checkuser const response someexternalfunction handleuserstate response react useeffect checkuser run once
facebookreact
combination of componentdidcatch and hook throw should have a queue this be likely a bug in react
Bug
do you want to request a feature or report a bug bug what be the current behavior if a component with hook throw an error in its render function after the hook have be define and that render error be catch via a componentdidcatch in a parent component any subsequent component will have their hook order jumble up on the next render this result in the app crash with an uncaught invariant violation should have a queue this be likely a bug in react please file an issue error or different message depend on the specific hook use if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below once load open the dev tool console and click the trigger re render button relevant source jsx function app prop const setcounter react usestate 0 return setcounter value value 1 trigger re render function errorthrow react usememo undefine if true throw new error return error component function statefulcomponent react usestate null return stateful component class errorhandler extend react component componentdidcatch error what be the expect behavior the app should not crash seeing as the componentdidcatch ought to catch the render error and allow the rest of the app to render as normal which version of react and which browser os be affect by this issue do this work in previous version of react this will presumably affect all version of react that include the current hook implementation v16 8 onwards
facebookreact
well error message when useeffect be call with no parameter
Enhancement
do you want to request a feature or report a bug feature what be the current behavior suppose you give an undefined object or forget to provide parameter to useeffect js const app react useeffect return reactdom render document getelementbyid container on jsfiddle this error stack be log uncaught typeerror create be not a function at commithookeffectlist react dom development js 17372 at commitpassivehookeffect react dom development js 17396 at htmlunknownelement callcallback react dom development js 143 at object invokeguardedcallbackdev react dom development js 193 at invokeguardedcallback react dom development js 250 at commitpassiveeffect react dom development js 18863 at wrap react development js 1353 at flushfirstcallback react development js 587 at flushwork react development js 699 at messageport channel port1 onmessage react development js 1093 though on a local project in react 16 8 4 this stack be log uncaught typeerror undefined be not iterable can not read property symbol symbol iterator at iterabletoarraylimit my project chunk js 123 at slicedtoarray my project chunk js 456 at mycomponent myfile js 7 what be the expect behavior neither of these be useful during the 5 minute it take to find the culprit useeffect that should have be a usestate in development we check for an undefined dep argument in useeffect and give a well warning which version of react and which browser os be affect by this issue do this work in previous version of react react 16 8 4 chrome on mac
facebookreact
be pass a ref to usememo consider cheat
Question
I have an object which be create via usememo I do not want this object to be recreate every time a certain dependency change and yet I want it to always see the late version of that dependency not just what it be upon initial creation currently I m do something like this bar change between render const latestfoo useref bar obj will only be create once yet it see the update latestfoo const obj usememo dosomethe use and or set latestfoo current latestfoo this feel like a little bit of a lie because it kindof depend on an update latestfoo current not really latestfoo the ref if that make sense yet it work fine as far as I can see not sure if I should feel bad about lie to usememo about its dep or if it s not really a lie at all and this be actually a totally expect use case of useref any tip be appreciate p s this be prompt by refactore my code after read this page which be an enourmous help in understand hook and write code that use they more consciously gaearon would you rather I post question like this somewhere else didn t see a comment section on the site and I don t use twitter
facebookreact
why function as child be not consider as child
Question
after dig deeply with this question I have find function as a child be not be consider as child take this example class countexpression extend react component render const child react child toarray this prop child console log child return react child count child one two still this will be ignore as child why this will be include in array that s fine so I would like know why be it so be it a bug or an expect behavior
facebookreact
useref only update with a usestate together
Question
do you want to request a feature or report a bug probably a bug what be the current behavior I m create a component swapper triggeredd by a interval I have to use the useref hook to keep the index state between render but it only get update when I keep a usestate the setcurrentindex be with it when the setcurrentindex at line 17 be remove the swapper doesn t work if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below please check it out what be the expect behavior I tought that the indexref wouldn t depend on the state hook to be update which version of react and which browser os be affect by this issue do this work in previous version of react react 16 8 4 chrome 72 0 os ubuntu 16 04
facebookreact
eslint plugin react hook usecallback circular dependency
Bug
bug question what be the current behavior when there s a function that mention itself wrap with usecallback or useeffect eslint plugin react hook will add the function to the list of dependency cause no use before define warning example js const updateandclean usecallback console log update something document removeeventlistener event updateandclean the idea of the function above be to clean after itself when there s no need for the event anymore I m sure there be well way to do that but for the sake of the issue let s presume this be valid code eslint plugin react hook would propose add updateandclean to the list of dependency js const updateandclean usecallback console log update something document removeeventlistener event updateandclean updateandclean cause no use before define warning line 17 updateandclean be use before it be define no use before define question be be this ok to leave as be would use the function before define it break any usecallback optimisation can eslint plugin react hook not automatically fix that since it cause other warning know the function need to run once can I pass an empty array to usecallback
facebookreact
maximum update depth exceed in control way
Question
do you want to request a feature or report a bug maybe bug what be the current behavior my case be that I want to update state n time by add different type of field to the state and then render they every updating of dom add new field I have to check whether I should do something more by check the hight of add element for example add a break between element field be represent by the tree structure of datum so I create the class which help I with go through the tree of field and I keep it in the class property I know how many time I have to modify the dom so it will be a fully control way of state update and it will finish after all field be add to dom but before I render all field I be get the error maximum update depth exceed do you know how I can handle with such a problem I find a solution by add settimeout on the way but I be not sure that be the clean solution comment code be it ok that I keep in component class property more complex class to manage structure of datum I be provide a simple example in codepage which show the problem and throw the error
facebookreact
usereducer eagerreducer optimization discussion question
Bug
I d like to continue the discussion start by I under a recent blog post by dan as encourage by dan r32694433 just to summarize what I ve stumble upon when experiment with usereducer after read that hoist declare in render reducer be treat differently I ve want to explore how they be handle by react 1 I have no idea how to reenter eagerreducer calculation after first schedule work after render get fully process commit this might very well be just I not understand how fiber work but currently I m confused by this it doesn t enter this code branch because fiber expirationtime be not 0 nowork and the work get schedule right away any pointer regard this be this valid might this be a bug somewhere 2 the logic around reducer bailout be somewhat iffy for I maybe it s just a matter of mention those in the documentation not every reducer update can bailout from render if the action queue get process in the render phase then it s just not possible we be already render after all action queue get process in the render phase for reducer declare inside render this mean that any new state computation might depend on the fresh prop this be not the case for the bailout mechanism though it s only possible to perform a bailout when dispatch an action so when we do not have access to the fresh prop should this restriction be mention in the docs imho this behaviour be inconsistent for the great good so it s acceptable but I think it should be document because it s slightly inconsistent people might trip over this note I m happy to provide documentation change if need I d like to discuss those point first to get a well understanding of thing
facebookreact
shallow renderer wrong initial state pass to getderivedstatefromprop
Bug
demonstrate in when gdsfp return a state change cdu do not seem to be call by the shallow renderer I m not sure how to make a simple test case but the identical enzyme test pass for mount ie when use react itself but fail for shallow when use the shallow renderer enzyme doesn t have any logic for call or interact with getderivedstatefromprop so I suspect it s not an issue with enzyme but it might be
facebookreact
setstate in useeffect cause a react state update on an unmounted component warning
Bug
do you want to request a feature or report a bug bug what be the current behavior the warning be trigger after an intricate sequence of event I stumble upon it by accident assume it be an error in my code but then step by step remove everything in my application until I be leave with a fairly small bit of code that doesn t seem to be do anything illegal from the api point of view yet be trigger a warning if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem the example be my real application code trim down as much as possible to demonstrate the warning so some of the code might be a bit nonsensical contrive but that s because I remove lot of surround code leave only the relevant bit for reproduce the issue in other word there might weird looking use of useeffect and weird sequence of thing but that sort of fall out of how I ve structure my route state component in the full app etc what be the expect behavior I would like to know if a be this a react bug that I stumble upon that should be fix b be this something I m do wrong and how I could fix that in my application I e be this a real memory leak be cause because of the way I structure the code which version of react and which browser os be affect by this issue do this work in previous version of react 16 8 4
facebookreact
react hook usestate update an array
Question
do you want to request a feature or report a bug hook clarification what be the current behavior I m try to understand the lifecycle of usestate I have a mock application use a mock websocket every second it send a new message from the backend the new message be mean to be append to an array use usestate here be a few different example that highlight my confusion example 1 in this example if I set the websocket s onmessage function once in useeffect then whenever I call setmessage to update the message array the message array I receive as an input be empty js const message setmessage usestate function receivemsg msg setmessage message concat json parse msg datum useeffect function if isundefine socket let ws new mockwebsocket ws 127 0 0 1 8080 ws onmessage receivemsg the effect of this be that I only ever get the late message in my array example 2 if however I set the onmessage function on every render as in this example then I get my full array with datum append as I would expect js const message setmessage usestate function receivemsg msg setmessage message concat json parse msg datum if isundefine socket socket onmessage receivemsg useeffect function if isundefine socket let ws new mockwebsocket ws 127 0 0 1 8080 ws onmessage receivemsg in the receivemessage function my message array be the whole array instead of an empty one in this example example 3 but if I assign a new reference to message as in this example and re assign the value inside receivemsg then I don t have to re assign the onmessage function over and over js const message setmessage usestate let msgref message function receivemsg msg msgref msgref concat json parse msg datum setmessage msgref useeffect function if isundefine socket let ws new mockwebsocket ws 127 0 0 1 8080 ws onmessage receivemsg example 4 but if I assign a new reference and don t re assign to it as in this example I continue end up with an empty array this suggest it s the assignment back to msgref that be keep the entire array within the closure js const message setmessage usestate let msgref message function receivemsg msg setmessage msgref concat json parse msg datum what be the expect behavior my original expectation be that example 1 would work I can tell there s something I m not totally understand about the way the assignment of variable to closure work with this hook but I m struggle to define what exactly s go on can someone shed some light on why this work this way which version of react and which browser os be affect by this issue do this work in previous version of react react 16 8
facebookreact
should set state inside discrete event cause cleanup to run
Question
this bug be pretty confusing I think it happen because fn schedule by setinterval fn 0 jump in front of the run effect cleanup cause by setrunne false so the interval still fire overwrite setlapse 0 that happen during the event with its setlapse somevalue this remind I of the issue describe in issuecomment 460409609 or at least a part of it in fact this problem exist even for regular react keystroke and other discrete event the solution to that would be to flush passive effect before we get a discrete event but here it seem like this wouldn t be sufficient because the effect flip as a result of the click not before it so should setstate inside a discrete event also flush passive effect seem like not that would defeat the purpose of delay they so this be work as design and the fix be just uselayouteffect when the timing matter or the raf solution
facebookreact
datum reactroot lose in server render if element inside
Bug
do you want to request a feature or report a bug bug what be the current behavior call rendertostre on hello produce hello however many other combination of dom root element within invisible react element be render without datum reactroot e g all of the follow produce hello without datum reactroot hello hello hello hello if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below see above what be the expect behavior I assume that any of the above example should produce markup include datum reactroot on the div element which version of react and which browser os be affect by this issue do this work in previous version of react issue present in all version 16 7 0 possibly early version too this be a minor issue I guess would only affect where the markup be rehydrate on client side use render rather than hydrate usage which be discourage however use render to rehydrate be still officially support I can implement a fix and make a pr but can anyone confirm that the expect behavior be what I think it be and that this be indeed a bug
facebookreact
exhaustive dep support for dynamic array
Question
maybe it s antipattern and maybe it isn t note how I leverage dep for createdat subselect ts const tasklist functioncomponent const tasklist useappstate state state tasklist const sortedtasklist usememo return object value tasklist sort a b a createdat b createdat eslint disable next line react hook exhaustive dep object value tasklist map item item createdat const child usememo return sortedtasklist map tasklist sortedtasklist return child
facebookreact
mislead error description when use wrong useref
Bug
there s a misleading error when use wrong the useref hook function mycomponent let nameref useref return see the example here the code above lead to this error function component can not have ref do you mean to use react forwardref I m move some class component to hook and stumble upon this and it take I a while due to the wrong error message
facebookreact
act should keep flush passive effect until there be none leave
Bug
currently act will flush passive effect at the end of a batch of work but if the effect themselves schedule additional work and that work schedule more effect act doesn t flush those what it should do be keep flush effect in a loop until there s nothing leave to flush
facebookreact
warning when assign to ref in render phase
Enhancement
do you want to request a feature or report a bug feature what be the current behavior there be no warning when assign to ref current in render phase what be the expect behavior give that this mostly work now but may cause issue on release of concurrent mode it would be helpful to have a warning when assign to a prop outside of useeffect e g I recently write this code which work fine at the moment and didn t realize the possible issue until gaearon point out the miss useeffect js export function usedidchange value let ref useref let didchange ref current value ref current value return didchange if a warning be not possible due to the lazy initialization pattern perhaps an eslint rule may be a solution which version of react and which browser os be affect by this issue do this work in previous version of react all version
facebookreact
uselayouteffect in ssr
Question
hi I do not understand the situation with this hook a bit I use this hook to perform the animation synchronously with the state update if I use useeffect then I have jump in the animation because the animation library do not have time to start also the documentation state that uselayouteffect run on the same phase as componentdidmount that be on the client side and here my server issue complaint to I about my code why be that originally post by dimensi in issuecomment 466023638
facebookreact
the component be not update when a new state be change use a callback from usestate
Bug
this be a bug I ve spend a lot of time try to localize the bug and have end with the follow minimal example jsx import usestate from react function app const imageurl setimageurl usestate const meaninglessvalue setmeaninglessvalue usestate 0 return setimageurl set picture 1 setimageurl set picture 2 setmeaninglessvalue meaninglessvalue 1 change another image prop function delayedimage src const previoussrc setprevioussrc usestate const isloade setisloade usestate false console log image be render with previoussrc src isloade if src previoussrc setprevioussrc src setisloade false console log image unload const handleload setisloade true console log image load return reactdom render document getelementbyid root live demo step to reproduce 1 open the demo 2 wait until the image be load become opaque 3 click the set picture 2 button 4 wait a bit while the image be load expect result the second image get opaque after a few second the delayedimage component get rerendere with the new state actual result the image stay translucent despite the new state that should make it opaque I reproduce the bug with react 16 8 2 in safari 12 0 3 and chrome 72 0 3626 109 on macos 10 14 3 didn t try other version more detail about the example the delayedimage component be an image that get translucent while be load the information about whether the image be load or load be store in a state use the usestate hook the other state hook be use to check whether the image url have change like in the faq example how do I implement getderivedstatefromprop when the component be render for the first time it work as expect it be translucent while the image be load and opaque after the image be load when the src prop be change by click the set picture 2 button the image get translucent but doesn t get opaque when it s load accord to the console message the correct value isloade true be set to the state but react doesn t rerender the component react rerender the component with the correct state when any other delayedimage prop be change by click the last button or change a prop use redux dev tool
facebookreact
why move item to another array fire re render for itself the item
Question
hello I have the follow problem when I drag drop item to an another array it re render the item I move why when I drag drop in the same array it s not render so it s good the problem be my deep child I have a little fetch to retrieve some additional datum these datum be already fetch so when I drag drop I don t want another fetch event react memo solve the problem you can check the console of codesandbox to see the problem what be the expect behavior no re render of the item since react already display it I just move to another array it s still the same item which version of react and which browser os be affect by this issue do this work in previous version of react react 16 8 1 macos 10 14 2 react beautiful dnd
facebookreact
simple memo component be update with new set of prop during context change
Bug
do you want to request a feature or report a bug bug what be the current behavior simple memo component receive new prop during context change if their parent get rerendere if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below what be the expect behavior conceptually from the user s perspective react memo component react memo component shallowequal should behave exactly the same but they do not which version of react and which browser os be affect by this issue do this work in previous version of react current react s master 0e67969cb1ad8c27a72294662e68fa5d7c2c9783 current late release 16 8 2 I ve already write a fail test for this would love to work on fix this but as mention in this pr I would require some guidance on how this should get fix properly
facebookreact
hook usestate one off callback
Question
do you want to request a feature or report a bug question feature I ve be try to handle a case where I need to execute a piece of code right after the state be set at a particular place in the code I do understand I m suppose to use useeffect to respond to change in state like so javascript const val setval usestate null useeffect handle change to val here val but the problem be it will run on all change make to val anywhere in the code without the second argument of setval be a callback that ll run after the state be set how can I execute something after a specific setval function call set the state
facebookreact
can not type chinese in under control mode reactdom 16 8 2
Bug
do you want to request a feature or report a bug bug what be the current behavior can not type chinese in under control mode when use react dom 16 8 2 via cnd if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below 1 switch ime input method editor into chinese 2 try type any letter you can only get english letter but not chinese character image what be the expect behavior can type chinese character image which version of react and which browser os be affect by this issue do this work in previous version of react not work in react dom 16 8 2 but work well in react dom 16 8 1 relate update it s wire that use react as a
facebookreact
react dom server renderstaticmarkup return empty string server side
Question
do you want to request a feature or report a bug bug what be the current behavior I m try to extract the initial html from react code on the server side to do this I m use the official react dom server library function rendertostaticmarkup reference here rendertostaticmarkup I m read a react source file transpile the jsx and es6 syntax to commonj use babel and then parse the evaluate commonj to rendertostaticmarkup react code jsx import react from react class test extend react component render return hello world export default test server side code javascript const rendertostaticmarkup require react dom server const babel require babel core const fsp require fs promise async let filecontent await fsp readfile test js utf 8 let code babel transform filecontent preset babel preset env babel preset react comment false minify true code let result rendertostaticmarkup code console log result package json json dependency babel core 7 3 3 babel preset env 7 3 1 babel preset react 7 0 0 react 16 8 2 react dom 16 8 2 what be the output use strict object defineproperty export esmodule value true export default void 0 var re act interoprequiredefault require react function what be the expect output hello world which version of react and which browser os be affect by this issue do this work in previous version of react json react 16 8 2 react dom 16 8 2
facebookreact
call setstate during component rendering cause incorrect previous state value in next state update
Bug
do you want to request a feature or report a bug bug what be the current behavior counter value be 1 if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below what be the expect behavior counter value should be 2 which version of react and which browser os be affect by this issue do this work in previous version of react firefox chrome 16 8 1
facebookreact
trigger suspense from hook
Bug
do you want to request a feature or report a bug question this may also be relate to 14563 how do we trigger suspense from a hook why do the question come up this question come up during our usage of react i18next a recent update of react i18next provide the usetranslation hook which allow obtain the current translation and will also trigger loading of not yet load translation namespace kinda like code splitting to handle the case where the translation aren t load yet the usetranslation hook throw a promise to trigger suspense which be actually really neat because it cleanly integrate with the exist react feature however if you be use more hook after call the usetranslation hook these other hook win t be render if usetranslation throw the promise once the translation have load the hook win t throw anymore and react will award you with a big red warning that the amount of hook have change example js const component const t usetranslation translationnamespace const count setcount usestate 0 return setcount count 1 t the count be count if translationnamespace isn t load yet usetranslation will throw cause usestate to not be render once translationnamespace be load usetranslation win t throw anymore which cause usestate to be render cause the warning the general case so this question doesn t apply to react i18next only but instead apply to all hook that wish to trigger suspense how would we go about do this and how would this integrate with the current rule of hook that state that hook mustn t be render conditionally
facebookreact
shallow renderer doesn t update on setstate with hook
Bug
see the issue and the test case with original fix in we ll need to fix it properly see issuecomment 463277621
facebookreact
prop reassignment in component
Question
do you want to request a feature or report a bug bug what be the current behavior prop reassignment in component if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below 1 have a parent component that pass a prop to a child 2 have a child assign the prop to the state default 3 unpack the state value and use a push to alter it 4 watch in horror as both the prop and the state change check child js what be the expect behavior prop should not be reassignable within mount component which version of react and which browser os be affect by this issue do this work in previous version of react all browser all os s react 16 7 0
facebookreact
an update to the state from usestate be not register in event handler ontransitionend
Bug
do you want to request a feature or report a bug bug what be the current behavior when update the state from usestate doesn t actually update the component in this case it be be update on an event handler I use console log to verify that it be be call yet no update in the component be be dispatch it s like react doesn t register that it want to update the state might want to throw out that I m new with this react hook and it could be something that I m miss if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react I ve setup a simple example showcase my issue I also include an implementation with the old class syntax and when do it with class it work fine here be the link to the codesandbox this example be take from my project I m fade out and translate upwards so I want to keep the text until the animation be do what be the expect behavior the component should update with the new register state when try to update state in a event handler which version of react and which browser os be affect by this issue do this work in previous version of react react v16 8 react dom v16 8
facebookreact
unmount an empty component be break with reactdom portal
Bug
do you want to request a feature or report a bug bug what be the current behavior when unmounte a component that have a child be render under a different parent with portal react be throw an error if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem what be the expect behavior component should unmount normally which version of react and which browser os be affect by this issue do this work in previous version of react 16 8 1 issue also happen with 16 7 0 the issue be only happen under very strict condition the component be render with reactdom portal modal should not render any html the parent component panel should render modal as the first component under avoid this be as simple as move modal under some other html I m not entirely sure this be an issue or I m just do something wrong with fragment and portal the actual error be throw be react dom development js 9254 uncaught domexception fail to execute removechild on node the node to be remove be not a child of this node
facebookreact
module mock yield unexpected act error
Question
do you want to request a feature or report a bug bug what be the current behavior I be try to figure out where be the good place to put a module mock accord to the new react version 16 8 1 if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below javascript import react from react import act from react dom test util import mount from enzyme import getpointsfromgroupid from util getpointsfromgroupid import tdashbody from jest mock util getpointsfromgroupid getpointsfromgroupid jest fn promise resolve const getdefaultprop currentgroup 0 describe dashbody let component beforeeach act const prop getdefaultprop component mount describe render it should render without explode expect component tobedefine what be the expect behavior this test pass but the placement of the mock module call give I the act error warn an update to tdashbody inside a test be not wrap in act when test code that cause react state update should be wrap into act act fire event that update state assert on the output this ensure that you re test the behavior the user would see in the browser learn more at I react wrap test with act which version of react and which browser os be affect by this issue do this work in previous version of react v16 8 1 run chrome on window 10
facebookreact
under what circumstance unstable shouldyield will return true
Question
in scheduler js function unstable shouldyield return currentdidtimeout firstcallbacknode null firstcallbacknode expirationtime currentexpirationtime shouldyieldtohost unstable shouldyield return true when currentdidtimeout be false and shouldyieldtohost return true but why shouldyieldtohost function return framedeadline getcurrenttime shouldyieldtohost return true mean there s no time leave in this idle period currentdidtimeout be false mean the schedule be not timeout what relationship between they why do unstable shouldyield depend on they
facebookreact
question reactdom render call in useeffect delay until first update
Bug
do you want to request a feature or report a bug a question maybe a bug but more likely a misunderstanding on my side what be the current behavior call reactdom render from within a useeffect win t actually render to the dom unless an update be trigger from anywhere else within the entire react app if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below see what be the expect behavior after the rendersanotherroot component be initially render the useeffect function be call and then the subsequent reactdom render call render the separate react root note uncommente the setcount update from within the rendersanotherrootwithupdate component will then render the content from both useeffect render call which version of react and which browser os be affect by this issue do this work in previous version of react react 16 8 1 react dom 16 8 1
facebookreact
warn when a memoize component use both hook and suspense
Bug
do you want to request a feature or report a bug bug what be the current behavior there be a warning show in the console for a component which have all the follow condition meet it be memoize use react memo it use hook it use suspense there be a promise throw text of that warning warn componentname render more hook than during the previous render this be not currently support and may lead to unexpected behavior if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below what be the expect behavior no warning should be show because the rule of hook be meet also the behavior should be consistent no matter if react memo be use or not which version of react and which browser os be affect by this issue do this work in previous version of react react 16 8 1
facebookreact
useimperativehandle behave as if input be by default
Bug
useimperativehandle have bug in 16 8 1 if you want to access any state will get the initial state not current state but in 16 8 0 alpha 1 it work good you can see here open console when you change input value will get the currently value in console but if you click button get value from ref will get initial value e if you try same here with 16 8 0 alpha 1 when click button get currently value
facebookreact
react cache alphas don t work with 16 8
Question
react cache be not publish with 16 8 1 like the rest of the react package this mean that the platform s suspense stuff will not work originally post by jaredpalmer in issuecomment 461170282
facebookreact
act be not really helpful when set state from promise callback
Duplicate
do you want to request a feature or report a bug feature what be the current behavior wrap in act doesn t help because setstate be call later on another tick so warning be print in a console what be the expect behavior some way to test code like this without get warn in a console about wrap inside act which version of react and which browser os be affect by this issue do this work in previous version of react 16 8 0
facebookreact
act can not detect secondary update
Question
do you want to request a feature or report a bug bug what be the current behavior if a component perform a second non user trigger update act can not detect it and warn about the update for example a button be click and update its text after a second the button reset and its text revert to its original state the reproduction be a bit contrive but demonstrate the issue what be the expect behavior the test run without warn about be wrap in act which version of react and which browser os be affect by this issue do this work in previous version of react react react dom 16 8 0
facebookreact
warn for act even when code be wrap inside it
Question
do you want to request a feature or report a bug report a bug what be the current behavior react test renderer emit a warning to wrap code inside act even though it be if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below here be a codesandbox with a component use usestate that toggle a div on off on a button click the test find the button call the onclick on the prop this would be follow by a snapshot test however no matter how I try and wrap the code in act the warning persist make sure to open the test tab on the right and to expand the console at the bottom image what be the expect behavior there should be no warning which version of react and which browser os be affect by this issue do this work in previous version of react this work fine with react 16 7 0 alpha 2 snapshot and all
facebookreact
referenceerror document be not define var actcontainerelement document createelement div
Duplicate
react v 16 8 I m use jsdom and enzyme to unit test my lib when I update to v16 8 this morning I start get the follow I think it have to do with the fact that test util be a js iife and the jsdom document object have not be create yet user n0280500 document dev reacttool inform node module react dom cjs react dom test util development js 944 var actcontainerelement document createelement div referenceerror document be not define for more context I have a setup file that get execute before any of my enzyme test as describe by the doc
facebookreact
unable to use usecontext hook inline in context provider
Question
do you want to request a feature or report a bug not sure if it be a bug or a feature yet this relate to hook it could also be that this be all expect behaviour and one of the workaround mention be require what be the current behavior I have a hook that depend on the usecontext hook use it as follow work perfectly const myhookedcomponent const contextvalue usecontext democontext return do something with contextvalue const mycontextprovidercomponent return what if I want to use the getcontext hook inline in the same component that declare the democontext provider const mycontextprovidercomponent const contextvalue usecontext democontext of course this fail due to the context hierarchy return do something with contextvalue I seem to be unable to get this work please note I have a very good reason for solve my issue with context and not pass prop the implementation I show above look trivial and dumb but it be the simple way to illustrate what the use case be in my implementation the provider sit in a complex component that do a lot of datum management which I really want to happen at this level the usual way to use this will be the first work version I note above it be only in the case where the user would want to use the hook inline inside the provider I have search for a couple of hour and try various configuration without success so my apology if this be a duplicate of another issue what be the expect behavior any method to consume context inline in the provider use the same re usable hook without have to revert back to render prop I know I can solve this with render prop but I be try to convert an implementation use render prop to hook I also know I can hoist the context provider high up but in my implementation it would quadruple the code complexity to develop and maintain while introduce extra complexity into the user interface also by extract the body inside the provider to a new component I can also solve this but ideally I would not like to have a user do this for this use case
facebookreact
hook usecontext with usestate not update
Question
do you want to request a feature or report a bug seem it s a bug what be the current behavior nest context provider and usecontext hook seem to be conflict update get discard what be the expect behavior when connect to a context it should update whenever it s value change which version of react and which browser os be affect by this issue do this work in previous version of react react 18 8 0 alpha 1 also reproduce on 16 7 0 alpha 0 browser chrome 71 os macos sierra more detail while work on a cleanup of a localstorage connection I try to mix 2 article 1 how to avoid pass callback down 2 update context from a nested component from the official react documentation I ve implement it with hook but the value seem not to be pass through I ve put up a streamlined demo on codesandbox 3 the actual implementation be only a couple of line more parse it from and stringifye it to json workaround that I find if I create a new function on each render around the setvalue function it actually work but this go against the advice on 1 how to avoid pass callback down about avoid create new value migrate it to a class and use componentdidupdate instead of useeffect I m actually use this right now as it work include save a reference to the function in the state be there anything that shouldn t work on the code below the effect get trigger with the change but the value doesn t get update on the component that consume via hook see repro code 3 javascript const createlocalstorage key const initialvalue localstorage getitem key const valuecontext createcontext initialvalue const settercontext createcontext const usestorage valuecontext settercontext map usecontext const provider child const value setvalue usestate initialvalue useeffect console log effect value localstorage setitem key value value return child return provider usestorage 1 how to avoid pass callback down 2 update context from a nest component 3 hlcecpq
facebookreact
original error message be swallow in an edge case with render phase update
Bug
can not set property memoizedstate of null js regression test fit do not swallow original error when update another component in render phase let usestate react let setstate function a const setstate usestate 0 setstate setstate return null function b setstate throw new error hello expect reacttestrenderer create tothrow hello
facebookreact
will dangerouslysetinnerhtml generate more html element
Invalid
do you want to request a feature or report a bug hi react team thank for your awesome work I have a problem when use dangerouslysetinnerhtml what be the current behavior my example code like this the node topic be a string render const node classname style this prop return but I get unexpected html that look like image image what be the expect behavior it s hard for I to debug what s wrong with it it s sometimes work but sometimes will generate a tag maybe the tag be generate by my browser which version of react and which browser os be affect by this issue do this work in previous version of react react 16 7 0 react dom 16 7 0 os macos 10 14 1 beta 18b73a chrome 71 0 3578 98
facebookreact
react router can t pass hook
Question
this be actually an issue of react router but since it s the major routing lib I want to make you aware that there be issue when you want to pass custom hook via prop through your component tree since route with react router be a regular use case and react hook be an easy elegant way to manage state through the app they should work together otherwise react hook be about create hook limit to just one component and you can not share state hook component wide maybe I didn t get something right and there be a way
facebookreact
componentdidmount inside a class cause a memory leak
Question
hi I have a very weird memory leak that seem to be relate to componentdidmount declaration memory be not free after unmounte component use code version react 16 7 mode developper or production same behaviour here be the code I use to hide or display a list of item class item extend react component componentdidmount render return test item class item extend react component constructor prop super prop this state renderlist let item for var I 0 I 4000 I item push return item ondisplay this setstate display true onhide this setstate display false render return display hide this state display this renderlist null reactdom render document getelementbyid app step to reproduce case 1 use google chrome and display the performance monitor to study js heap size and dom nodes 1 click on display the list of 4000 item be display 2 click on hide the list be unmounted when you look at performance monitor you can see that around 8000 node be still in memory and js heap be high than before mount component as well if you redo 1 and 2 multiple time you will see node go to 16000 then go back to 8000 etc thus memory be free after the first unmount operation but the first one be not the weird thing be that if you do 1 2 2 2 then it be free case 2 use the same code but remove the componentdidmount function in the class do 1 and 2 then after few seconde memory be free automatically node and js heap expect behaviour behaviour expect I be expect that the memory would be free after unmounte a component like in the 2nd case that s a real issue when you mount unmount big list multiple time then js heap be go very high
facebookreact
useimperativehandle should warn when second arg isn t a function
Enhancement
I ve notice a strange bug with the react redux forwardref opt in if I use it with a connect class component everything be ok javascript const mycomponent class test extend react component foo console log print foo from test component render return null const connectedcomponent connect null null null forwardref true mycomponent const store createstore function app return if ref ref foo const rootelement document getelementbyid root reactdom render rootelement if I use it with a connect functional component that use forwardref with useimperativehandle I obtain a strange error create be not a function in commithookeffectlist react dom method javascript const mycomponent react forwardref prop ref useimperativehandle ref foo console log print foo from test component return null const connectedcomponent connect null null null forwardref true mycomponent const store createstore function app return if ref ref foo const rootelement document getelementbyid root reactdom render rootelement I create a codepen to reproduce the issue ps sorry for the cor error but I don t find the way to add react next as cdn
facebookreact
how will react solve nest context
Question
js js value1 value2 value3 value4 value5 null
facebookreact
what s the difference between fiber reconciler sync mode and the old react 15 stack reconciler why do performance boost so much
Question
since performance of react 16 boost so much and thank to those aweosome talk on youtube explained fiber so detail I hardly figure out even the late version of react 16 be still in sync mode no feature like time slicing be turn on by default then I wonder why the perfmance be pretty good compare with react 15 even though try to get some info on google but it seem like no one really look into this question even react 16 be ship with this fake fiber mode for such a long time it be not well document or explain on the official website can someone give I some idea about this please
facebookreact
override updater in react class doesn t have any effect or error
null
do you want to request a feature or report a bug feature what be the current behavior override updater in react class doesn t have any effect or error what be the expect behavior maybe there should be a reserve word list in react doc to prevent anyone from do this accidentally or add warning for override these word javascript class app extend react component state count 0 updater this setstate state count state count 1 render return this state count warning expect onclick listener to be a function instead get a value of object type in button create by app in app
facebookreact
unable to catch error emit in componentdidmount
Question
do you want to request a feature or report a bug bug report what be the current behavior error boundary handle error emit in componentdidmount and somewhy rethrow it javascript class errorboundary extend react component constructor prop super prop this state error null errorinfo null componentdidcatch error errorinfo this setstate error error errorinfo errorinfo render if this state errorinfo return I ve handle an error return this prop child class mycomponent extend react component componentdidmount this setstate throw new error this error somewhy be rethrown render return this component be awesome reactdom render document getelementbyid approot what be the expect behavior it should not rethrow the error which version of react and which browser os be affect by this issue do this work in previous version of react react 16 7 0 os win 10 x64 browser chromium 71 0 3578
facebookreact
concurrent mode io hover behaviour
Bug
I hope this be the place to submit issue regard concurrent mode I don t know if this be a bug or intend behaviour but I have a situation where the my react app behave differently depend on the use of concurrent mode here be a link to a codesandbox demo the behaviour on mobile safari on io 12 1 2 be different whether use reactdom render vs reactdom createroot when reactdom render be use a tap result in an alert and after the alert be dismiss the hover style be apply when use reactdom createroot a tap result in the hover style be apply a second tap be need to invoke the click handler this double tap behaviour from io be describe here shouldn t the two render method behave the same in this regard or be this really intend behaviour btw a settimout arround the mouseenter event handler body do make reactdom createroot behave the same way as reactdom render
facebookreact
throw an error from a component while server render change the default value of a context if there be a provider in that tree
Bug
do you want to request a feature or report a bug report a bug what be the current behavior throw an error from a component while server render change the default value of a context if there be a provider in that tree if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below jsx import react from react import rendertostre from react dom server let theme react createcontext light let throw throw new error some error try rendertostre catch e this should log light since it s the default value and there s no provider in the tree but it log dark instead console log rendertostre x x what be the expect behavior throw an error from a component while server render shouldn t change the default value of context which version of react and which browser os be affect by this issue do this work in previous version of react I think this be break in all version of react with new context here s a codesandbox of the issue with react 16 3 0 it also only happen while server render it work correctly in the browser
facebookreact
warn it look like index be reassign its own this prop while render this be not support and can lead to confuse bug
Question
when I try to update react from 15 4 1 to 16 7 0 what s wrong with this
facebookreact
usecallback useeffect support custom comparator
Question
currently we can pass an array as second argument when use usecallback or useeffect like below js usecallback dosth a b a b how to do deep equal if a be an object the problem be it only compare array item with it there any way to compare complex object support custom comparator as third argument look not bad js usecallback dosth a b complexobject item previousitem custom compare logic return true false here
facebookreact
eslint plugin rule of react use undocumented context report signature
Bug
do you want to request a feature or report a bug possible bug what be the current behavior eslint plugin react hook currently use undocumented context report node message if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below everything work fine in late eslint for now what be the expect behavior eslint plugin react hook use document context report node message contextreport which version of react and which browser os be affect by this issue do this work in previous version of react eslint plugin react hook late I just notice when work on a tslint port and typescript report error on every context report usage I m happy to open a pr since a fix be pretty straight forward it look like a legacy signature that be still support since this be undocumented however it might break unannounced I test it quickly on my local machine and couldn t detect observable change in the report error from a quick dive it seem that positional argument be handle by l57 but this might only be an internal method hard to tell
facebookreact
q when should you not use react memo
Question
I ve be play around with react 16 6 0 recently and I love the idea of react memo but I ve be unable to find anything regard scenario well suit to implement it the react doc reactmemo don t seem to suggest any implication from just throw it on all of your functional component because it do a shallow comparison to figure out if it need to re render be there ever go to be a situation that negatively impact performance and second question as long as everything remain pure be there ever a situation to not wrap a functional component with react memo thank you
facebookreact
wrong visualization order in user timing when profiling in chrome
Bug
do you want to request a feature or report a bug bug what be the current behavior in the screenshot below the droptarget tile update should have be visualize above the tile mount similarly the item with stop icon to the right should have be in the first row image if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below sorry I don t have public demo when the bug happen it doesn t seem to be specific to a specific component lifecycle event I m not sure whether it s react s problem or chrome s what be the expect behavior different order which version of react and which browser os be affect by this issue do this work in previous version of react react 16 6 3 but I have see this in 16 4 0 too chrome 70 0 3538 110 window 10 home
facebookreact
shallowrenderer do not work with class contexttype
Bug
do you want to request a feature or report a bug bug what be the current behavior the shallow renderer from the react test renderer package do not work with class contexttype classcontexttype the component always receive an empty object as the context what be the expect behavior the shallow renderer should forward the context provide to the render method to the render component s this context which version of react and which browser os be affect by this issue do this work in previous version of react 16 6 3 step to reproduce the test below can be use to reproduce the problem open on codesandbox io the first test reproduce the bug and the second test show a workaround import as react from react import shallowrenderer from react test renderer shallow import proptype from prop type const testcontext react createcontext message test1 class testshallow extend react component static contexttype testcontext componentdidmount console log this context message render return this context message it shallow render with contexttype const result new shallowrenderer render message test2 expect result toequal test2 fail it workaround shallow render with contexttype testshallow contexttype message proptype string const result new shallowrenderer render message test2 expect result toequal test2 work the problem seem to be locate here l146 the function getmaskedcontext check the property declare on type contexttype and filter out the property from the context provide to the shallow render unless the type contexttype be declare
facebookreact
fail to execute removechild on node error on unmounte react portal with nulled child
Bug
do you want to request a feature or report a bug bug what be the current behavior when you render a portal with null child value if the portal be render in first place then the app crash and give the message uncaught domexception fail to execute removechild on node the node to be remove be not a child of this node but if you put the portal to render after the rest of component content it work like it should on a debug I realize that s the other node of component be remove like the portal create div be a parent of the other node of component that s the cause of this error if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below I do a example project after you run you need only to click the button to see the error what be the expect behavior unmount the component correctly which version of react and which browser os be affect by this issue do this work in previous version of react test react version 16 6 3 and I don t know if this already work on any previous version
facebookreact
setstate hook inside useeffect can cause unavoidable warning can t perform a react state update
Question
bug what be the current behavior example click on ok button cause warning can t perform a react state update on an unmounted component the problem that unsubscribe be call during b event setvisible v false call see log set visible before unsubscribe warn can t perform a react state update on an unmounted component this be a no op but it indicate a memory leak in your application to fix cancel all subscription and asynchronous task in a useeffect cleanup function in child create by holder set visible after in our case we have this even without raf call but on transitionend dom event it s occur randomly and rare in our codebase as transitionend event should be call exactly at need time but example show what happen seem like it occur only if you have a setstate call during useeffect callback like setrefresh v v 1 inside provide code after rewrite our codebase to avoid setstate call in useeffect the error have go code javascript import react from react import reactdom from react dom import mitt from mitt const emitter mitt const child const visible setvisible react usereducer s a a true react useeffect const handle console log set visible before setvisible v false this call cause unsubscribe and warn about state console log set visible after emitter on b handle return console log unsubscribe emitter off b handle return visible child text const holder const refresh setrefresh react usestate 0 const visible react useref true react useeffect if refresh 1 visible current false setrefresh v v 1 this state change from effect cause problem const handle setrefresh v v 1 emitter on a handle return emitter off a handle return visible current function app return emitter emit a requestanimationframe emitter emit b ok const rootelement document getelementbyid root reactdom render rootelement what be the expect behavior do not provide warning if unsubscription be call during setstate call which version of react and which browser os be affect by this issue do this work in previous version of react react 16 7 0 alpha 2
facebookreact
react hook linter fail with unusual for loop
Bug
do you want to request a feature or report a bug bug what be the current behavior react hook linter fail with this piece of code js function usehook const ref react useref 1 2 3 const re valid because there be not unexpected return if ref current for let I 0 I ref current length ref current I I re push ref current I react uselayouteffect however a bit more usual for loop be handle as expect js function usehook const ref react useref 1 2 3 const re if ref current for let I 0 I ref current length I re push ref current I react uselayouteffect what be the expect behavior skip for look without return which version of react and which browser os be affect by this issue do this work in previous version of react eslint plugin react hook 0 0 0
facebookreact
usereducer dispatch action be reduce twice
Bug
do you want to request a feature or report a bug report a bug what be the current behavior there be case where action dispatch by usereducer s dispatch function be reduce twice in concurrent mode as far as I can tell from my first quick read of the code of react dom so I might be totally wrong this happen when a high priority action be add to a queue that already contain low priority action on the first run that be cause by for example an onclick handler high priority the dispatch action be append to the queue on process the queue the low priority action for example from setinterval event be ignore and the onclick action be reduce but stay on the end of the queue so that on the next time the queue be process that action get reduce a second time see a testcase at press the button increment the button most of the time not always depend if tick action be in the queue by two what be the expect behavior I d expect a dispatch action to be only reduce once which version of react and which browser os be affect by this issue do this work in previous version of react test with react 16 7 0 alpha 2 on chrome 70 0 3538 110 and safari 12 0 1 both on macos
facebookreact
useeffect be break for react native with jsc
Bug
as report in open source facebook react native issue 21967 the useeffect hook be break for react native when use javascriptcore which affect both io and android this be because the settimeout branch of scheduler l463 l495 specify a 5000ms delay l483 this 5000ms be suppose to be the maximum expiration time but in this fork it end up be the minimum callback time unless another state update force we to sync flush pende callback since useeffect be passive this mean react win t call it until after a few second have pass I assume we react team haven t notice this because we re typically use the postmessage implementation but with javascriptcore react native end up use the settimeout fork I think this be break by commit 4d17c3f pr 13740 which intentionally change the delay under the mistaken assumption that it would only impact unit test if we want to avoid use settimeout for react native I think we ll need to add a scheduler implementation that do not require postmessage or messagechannel since javascript core do not support either
facebookreact
react 16 6 3 silently swallow an exception in reactdomserver rendertonodestream
Bug
this be reproducible with the follow snippet use strict const react require react const reactdomserver require react dom server function hello throw new error foo return react createelement div null hello world const stream reactdomserver rendertonodestream react createelement hello stream on datum chunk console log chunk tostre stream on end console log do stream on error err console error err react 16 6 1 emit an error event as expect but react 16 6 3 silently swallow an exception leave the stream in a broken state in which it never end this problem appear to be cause by this modification in reactdomnodestreamrenderer js diff 1090c7a359d6dc602b62ac38b66697b3l25 here stream destroy get call with an exception object but the actual handler stream destroy doesn t use it anywhere which result in ignore the exception
facebookreact
react ie
Question
do you want to request a feature or report a bug what be the current behavior if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below what be the expect behavior which version of react and which browser os be affect by this issue do this work in previous version of react
facebookreact
getderivedstatefromprop be user hostile
Question
so I think getderivedstatefromprop as design turn out to be user hostile the short summary be that it make the pattern describe in the doc use hoc for cross cut concern impossible for non trivial case imagine implement an hoc that listen to change event on a datasource but where a simple shallowequal on the resultant state isn t sufficient to prevent render I e what if you need more complex logic to determine if new datum from the datasource should be apply in my case I have a datasource that doesn t guarantee that it will give out object of the same identity so a check will always return false and cause a re render but I can do a little bookkeeping on the side and determine whether the datum be actually new and should therefore be load into state this lead to some problem 1 because getderivedstatefromprop be static it s not possible to store some internal bookkeeping datum on the component instance that get use to determine whether to query the datasource bad case this bookkeeping information could be stuff in the state object but that s unnecessarily constrain and a bit ugly from a code organization perspective 2 more importantly it s not possible to determine why getderivedstatefromprop be be call be it because of a prop change or be it because of a change event fire on the datasource this matter because if prop have change datum must be fetch and the component re render unconditionally but if the prop haven t change then it s possible all the datum load be the same as last time and so render can be skip here s an example use the deprecate api that s no long possible lightly edit from the hoc example I mention above function withdataloade component datasource getdatafunc return class extend react purecomponent componentdidmount subscribe to change datasource addchangelistener this handlechange componentwillunmount clean up listener datasource removechangelistener this handlechange componentwillreceiveprop prop unconditionally update state and rerender since the prop change const possiblynewdata getdatafunc datasource prop this this setstate possiblynewdata remember some metadata about what we fetch for next time this bookkeeping datasource bookkeepingdata handlechange update component state whenever the datum source change const possiblynewdata getdatafunc datasource this prop this if datasource didifetchnewdata this bookkeepe the datasource have update datum in it so rerender this setstate possiblynewdata remember some metadata about what we fetch for next time this bookkeeping datasource bookkeepingdata else no new datum be fetch so don t update state and don t rerender do nothing render notice that the behavior be different between componentwillreceiveprop and handlechange there s no way to make that distinction with the new api
facebookreact
re render lazy doesn t respect defaultprop on memo
Bug
with this js const add react memo prop return prop inner prop outer add defaultprop inner 2 const lazyadd lazy fakeimport add if I render lazyadd again after it resolve it win t get the inner default prop value this be a bug
facebookreact
reactdom render return null when trigger from setstate callback
null
I be not sure if it be bug or not but the behaviour be kind weird as show in the working demo here what be the current behavior the current behaviour be that when I render a dialog from onclick setstate callback like this this setstate a 1 this renderportal click I this renderportal will render the dialog however I can not close the dialog but when I do this renderportal click I I can close the dialog it seem that react think the dialog render from setstate callback be stateless why be that what be the expect behavior shouldn t these two snippet work the same way
facebookreact
usecallback return undefine when the component be render server side
Bug
do you want to request a feature or report a bug bug what be the current behavior react usecallback return undefine when the component be render server side if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below this bug can be reproduce by create a react component use a usecallback log the return value on the server yield undefined while it properly return the function in the browser you can observe this bug in this codesandbox the application be properly render to a string bug look at the console you will see that the return value of usecallback be undefined here s the exact same application but render on the client the function be properly log to the console what be the expect behavior react usecallback should return the memoize callback not undefined which version of react and which browser os be affect by this issue do this work in previous version of react react 16 7 0 alpha 2 react dom 16 7 0 alpha 2
facebookreact
regression react 16 automatically mark first item of a select with size 1 as check
Bug
do you want to request a feature or report a bug bug regression what be the current behavior in react 16 when create a size 1 the first child be automatically get mark as select in react 16 there do not seem to be a way to specify no get select by default what be the expect behavior in react 15 unless you mark an option to be select no option be select by default which version of react and which browser os be affect by this issue do this work in previous version of react reproducible in chrome 72 and firefox 59 note this be almost a duplicate of 12200 in fact I copy issue text and codesandbox example just change multiple to size 3
facebookreact
hook be disabled in v16 7 0 alpha 1
Bug
image smile
facebookreact
when use react lazy will cause the gpu cpu to run overload and the page be very slow
Bug
do you want to request a feature or report a bug bug what be the current behavior page be very slow as we can see from this picture react have be execute a work loop during the render suspend image image if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below what be the expect behavior I expect the page not to be stick which version of react and which browser os be affect by this issue do this work in previous version of react react16 6 3
facebookreact
finddomnode throw inside suspense
Bug
do you want to request a feature or report a bug bug what be the current behavior I have a component which listen for resize event via a blueprintjs resizesensor when load a component dynamically with lazy suspense an exception occur as the resize sensor appear to be unmounted uncaught error unable to find node on an unmounted component at invariant 29 chunk js 86295 at findcurrentfiberusingslowpath 29 chunk js 90628 at findcurrenthostfiber 29 chunk js 90640 at findhostinstancewithwarne 29 chunk js 106349 at finddomnode 29 chunk js 106869 at resizesensor componentdidupdate 29 chunk js 10535 the resize sensor should be remove listener on unmount l73 demo relate what be the expect behavior no exception be throw which version of react and which browser os be affect by this issue do this work in previous version of react test with react 16 6 1 fail react 16 6 0 work
facebookreact
setstateaction return from usestate hook dose not accept a second callback argument
Question
do you want to request a feature or report a bug question what be the current behavior the setstateaction return from usestate hook dose not accept a second callback argument it can not works like class componet s setstate method which receive a callback param and can perform the callback after this setstate action update if the current behavior be a bug please provide the step to reproduce and if possible a minimal demo of the problem your bug will get fix much fast if we can run your code and it doesn t have dependency other than react paste the link to your jsfiddle or codesandbox example below what be the expect behavior hope the setstateaction function can receive a second callback argument and can use like setstate method callback I have read the official note this technically do accept a second argument but it s already under a deprecation warn and it s not even release so probably well to not define it if instead it s work as intend how can I perform special action after this setstateaction call which version of react and which browser os be affect by this issue do this work in previous version of react 16 7 0 alpha 0
facebookreact
react memo and react lazy ignore proptype
Bug
do you want to request a feature or report a bug bug what be the current behavior proptype isrequire with react memo doesn t get trigger in the console when the require prop be undefined jsx import react memo from react import reactdom from react dom import proptype from prop type it should appear two proptype console error without memo it will throw the proptype error like it should const memobutton memo return memo button memobutton proptype memocolor proptype string isrequire it will throw the error in the console const button return button button proptype color proptype string isrequire const rootelement document getelementbyid root reactdom render rootelement edit 501jppv64n which version of react and which browser os be affect by this issue do this work in previous version of react js affect version prop type 15 6 2 react 16 6 1 react dom 16 6 1
facebookreact
rapid successive call to unload cache resource item in suspense result in a silent lockup
Bug
do you want to request a feature or report a bug report a bug what be the current behavior when use suspense trigger several very rapid non cache hit lock up the near parent suspense component until it be remount if the current behavior be a bug please provide the step to reproduce visit open devtool to show the network inspector click a post to view click the next button or focus it with your keyboard press space bar multiple time very quickly 6 should do inspect the network tab you ll find that some of the later post request do not happen at all and that any further post request make will also not be call what be the expect behavior all cache resource request should be call regardless of how quickly or how many pende request be currently inflight which version of react and which browser os be affect by this issue do this work in previous version of react react 16 7 0 alpha 0 browser 70 0 3538 77 official build 64 bit os macos mohave 10 14
facebookreact
eslint plugin react hook do not work with wrap component
Enhancement
js export const counter let count setcount if 0 1 count setcount usestate 0 return count const wrapper component component export const wrappedcounter wrapper let count setcount if 0 1 count setcount usestate 0 return count linter show an error in the first component but ignore the second one
facebookreact
suspense fallback remount when each child resolve
Bug
do you want to request a feature or report a bug not sure if its a bug or a feature request what be the current behavior the component give as a fallback to suspense be remount each time a lazy child resolve this example show how a fallback component which count up be mount more than once what be the expect behavior the fallback be mount once and be only unmounted when all lazy child be resolve in the example the counter would run up to 9 which version of react and which browser os be affect by this issue do this work in previous version of react