-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix editor launch freeze in debug mode when packager isn't running #3258
Conversation
Just noting that I wasn't able to reproduce this issue today (on |
On this branch I tried with Wifi on and was able to reproduce. But now I tried on |
Hey @ceyhun, 👋 I'm working on cutting the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd tried this a few days ago and it seemed to be working, but I tried again today and I'm still getting the freeze for 1 minute when running the code from the linked WPiOS PR. Here's my setup:
- I checkout the WPiOS branch (wordpress-mobile/WordPress-iOS@0b6371f)
- Run
rake xcode
- In Xcode, with a physical device connected via cable, I run the project (making sure I had no packagers running)
- My device was on a data connection (WiFi off)
- I open a new post on any of a number of sites and the app freezes for one minute before opening the block editor
The difference I notice, which you mentioned above, is that now when I open the editor, the Xcode log is much more verbose and includes fairly huge chucks of JSON that were not being displayed before IIRC.
Is your setup the same? I'm trying to figure out what accounts for the differences between what we see.
Oh, I wasn't testing with cellular data when Wifi was off, the phone I was testing with didn't have a sim card. Now I tried inserting one and I can reproduce on cellular data, even on this branch! The freeze still seems to happen here on line 94: But with that information, I think it makes sense to skip #if DEBUG
if isOnCellularNetwork {
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
}
#endif Not sure how to implement the |
I agree it makes sense that if WiFi is OFF and cellular data is ON, the app should use the prepackaged bundle instead of loading from the network.
I'm not sure I follow, your current changes already removed
We could use a lib like Reachability, I don't know of an easy way to do this without a library either. |
Oh sorry about that, there's another
That could mean adding that library to Gutenberg pod as a dependency, only to be used in debug mode of WPiOS :( I just found out about NWPathMonitor which is available on iOS 12.0+, maybe it's time for me to revisit this PR to bump deployment target to iOS 13 so we can use that :D |
Nice, TIL about
|
Wanna run full suite of Android and iOS UI tests? Click here and 'Approve' CI job! |
@guarani Implemented a solution with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on a real device on both data and WiFi connections and it worked as expected. I also tested to ensure the packager if running, is connected to successfully and also OK. Did a quick check on a simulator and it's also working great!
Thanks a lot @ceyhun! I think this can be merged to 1.50 if you'd like.
Updated milestone to reflect this! |
Thanks a lot @guarani! Merged the gutenberg PR already and updated the gutenberg reference to current |
Fixes #2944
Gutenberg PR: WordPress/gutenberg#29859
WPiOS PR: wordpress-mobile/WordPress-iOS#16094
I was able to reproduce this on a device. I observed that it only happens when you open the editor the first time and there's no delay on subsequent openings for me. Could be related to different network setups. I was able to fix the delay on the first run for my case, but can't know for sure if this will work in general.
The reason was that the
jsBundleURL
method, which calls a function that checks dev machine's local IP for a running server was being called multiple times during the editor launch:1- Initializing the
bridge
inisPackagerRunning
=> delegate owner calls it2- Getting the
sourceURL
inisPackagerRunning
=> we call itCurrently the lazy initialization of the bridge happens on this line:
let url = sourceURL(for: bridge)
, along with thesourceURL
call. So one line calls it twice :)I removed this and now only the bridge is lazily initialized inside the
isLoaded
method when it is accessed the first time and thejsBundleURL
is called once. This resolved the delay for me, but as a side effect when the editor is launched there's more verbose logging from the JS side to the Xcode console.To get around this, I first thought of eagerly initializing the bridge in Gutenberg class'
init
method and checking thebundleURL
property of the bridge in theisPackagerRunning
method. ButRCTBridge
's init method has a reference toself
as it'sdelegate
, so this can't be done oninit
and we need to change the delegate to be another class instead. I thought in the end this might require a lot of changes and chose to keep the verbose log during debug by removingisPackagerRunning
andlogThreshold
completely. Now thelogLevel
is set according to theDEBUG
flag and is the same whether the packager is running or not.The default setting for this in React Native is in
RCTLog.mm
:If a dev prefers the
trace
level threshold instead ofinfo
during debugging like it was before when a packager was detected, this can now be done manually in code by callingRCTSetLogThreshold(.trace)
in the initializer. But I feel like this shouldn't be the case because it's only one level below and also I couldn't find a call toRCTLogTrace
macro anywhere.Feel free to give this a spin and let me know if it fixes the delay for you too.
PR submission checklist: