When I call this.setState, the render() function is called.
If there is a problem in the render function, this.seState never completes. How can I figure out where in render() the error is?
I do a
console.log('before set state');
this.setState({isLoaded:true});
console.log('after set state');
and I see the first console mention be printed, but not the last one. However, in the iOS simulator there are no warnings or errors or anything. I can find the error by deleting one line at a time from render() and seeing when it stops crashing - but there must be a better way to debug this.
Any ideas?
setState itself calls for a render
from docs (https://facebook.github.io/react/docs/component-api.html) :
setState() will always trigger a re-render unless conditional
rendering logic is implemented in shouldComponentUpdate()
Related
In short, I have a table row with an onclick event. I am getting this via
const row = screen.getByRole('row', { name: /My row/i })
await userEvent.click(row)
This does not trigger the event handler. However, if I do:
const row = screen.getByRole('row', { name: /My row/i })
fireEvent.click(row)
This works fine.
I know userEvent uses more events to simulate a row click, but the event handler works fine in the live application too. Are there any reasons why userEvent might not work?
Like most very strange things, the problem lied elsewhere. But for documentation purposes, this was due to the app rerendering while doing my assertions. What would happen was this:
App renders, making a bunch of API calls
My API call for my test finishes, say, get user
findByText('My User') passes and gets me my DOM element
Another API call finishes, re-rendering the component to show this data
The result of findByText is no longer the current active DOM element
click fires
As its no longer in the document, there's nothing to click/fire an event
I changed my previous lines to check for ALL data loads before grabbing my row and it seems to consistently be working. This means I have to assert things unrelated to my tests, but that may be due to my app having poor UX with things popping in as they load?
Either way, I'm not 100% confident this is the reason, but if
userEvent.click is not firing events, or
toBeInTheDocument is failing, even if findBy worked
It may be due to your app rerendering after you've asserted everything has loaded. Hope I can save someone else 3 days of suffering like I had to to find that simple fact...
After receiving this error, the screen stops working ("Syncing files to Device Edge ...")
What could be the reason of this problem?
See code here.
I can't understand why it's happening. After this error my widget renders before async function fun.
Assuming ("Syncing files to Device Edge ...") is a async function, program waits for it to finish. But since you try to hotreload before, it can not respond. It is better to just stop the program and re-run again. Or refresh instead of hotreload
I have question. When we do quik(double click) actions pop()from screen and then push()to this screen. In this case dispose() and init()will be in wrong order. I think dispose shoul call first(pop) and then init(push) when we open screen. But actual result => first init and then dispose.How to fix it in flutter?
I noticed the same unexpected behaviour.
I tried to create a reproduced code https://github.com/antonio-nicolau/Flutter-beamer-with-flutter_hooks
please see logs and you'll notice dipose being called in reverse mode
I'm creating a SwiftUI multiplatform app in XCode and I have a section of my code that hangs. I want to update the user so they know what's happening and are willing to wait. I originally planned to have an alert with text that changed and then planned to have a Text element that updated. In both cases this isn't shown until after the code executes and as such only shows the final message (normally the success done message unless an error made it end sooner).
Is there anyway I can have a visible message to the user through an alert or SwiftUI element that is updated right away and thus will be helpful?
The fact that the alert isn't even shown until after the code executes is bad and incorrect. This suggests that you are doing something lengthy on the main thread, and that is an absolute no-no. You are freezing the interface and you risk the WatchDog process crashing your app before the user's very eyes. If something takes time, do it in the background.
In my flutter app I use this code to go to my dashboard page, but it fails to do so the first time and I get the debugLocked error.
The launch page in the app is a Router that checks for shared preferences "sessionid" which, if set, takes the user directly to the Dashboard, else takes them to the login.
Without the below code, I get to my Dashboard just fine, using Navigator.pushReplacement() but then, a back arrow appears on the appBar. This back button takes the app back to the Router.
I searched for answers on how to remove all screens from the navigator and the following was what I found.
Navigator.of(context).popUntil(ModalRoute.withName(Dashboard.id));
Using the above code gives me the debugLocked error. Is there a solution to mitigate this problem? Or is there any other efficient way for me to remove screens from the context? Does setting automaticallyImplyLeading to false help somehow? Because this error only occurs after someone has logged in or signed up.
to remove all the previous routes use Navigator.pushAndRemoveUntil()
This can be another alternative, if you for some reason face a setState error.
navigationService.popUntil((_) => true);
navigationService.navigateTo(
'authentication',
);
basically i wait until the navigation finish setting everything and then call the navigateTo.