Skip to content
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

CB-14045 - reinit url after app freezes #363

Merged
merged 4 commits into from
May 16, 2018

Conversation

svalaskevicius
Copy link
Contributor

Hi!

We've stumbled on a similar issue to this: https://issues.apache.org/jira/browse/CB-14045 although for us it takes a bit longer (10h or so of app being in background).

In our case the app resumes in a half working state, where the web view has been reinitialised pointing to about:blank with only default Js api available and no cordova js. Then, cordova tries to emit those resume and other events but all of them fail as there is no cordova js var available.

this approach does not fix app getting into that state as I am not fully aware how does it do that (12h debugging cycle is pretty hard).. but it gets it out of the broken state by pointing the webview back to the app's url.

what do you think?

Thanks!

@codecov-io
Copy link

codecov-io commented Apr 23, 2018

Codecov Report

Merging #363 into 4.5.x will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##            4.5.x     #363   +/-   ##
=======================================
  Coverage   63.45%   63.45%           
=======================================
  Files          14       14           
  Lines        1691     1691           
  Branches      284      284           
=======================================
  Hits         1073     1073           
  Misses        618      618

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update acf9107...56f5dc6. Read the comment docs.

@@ -720,12 +720,25 @@ - (void)onAppWillTerminate:(NSNotification*)notification
}
}

- (void)checkAndReinitViewUrl
{
if ([[[self.webViewEngine URL] absoluteString] isEqualToString:@"about:blank"]) {
Copy link
Member

@shazron shazron Apr 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the unlikely scenario that appURL is actually about:blank, you should check for this condition.
RIght now there is no probability of an infinite loop, but you never know if there are side-effects with any calls further down the stack in checkAndReinitViewUrl

I would return a BOOL from this function (YES if it re-inited, NO if it did not), and add a unit test in https://github.com/apache/cordova-ios/blob/master/tests/CordovaLibTests/CDVViewControllerTest.m

Copy link
Contributor Author

@svalaskevicius svalaskevicius Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! I'll try to update these when I have a chance :) we've found another case when testing the loaded url in the webview is (null), so added those checks too

@svalaskevicius
Copy link
Contributor Author

Hi @shazron , I've changed the function as requested, however I'm having problems with the test...

I've tried adding this test:

-(void)testIfItLoadsAppUrlIfCurrentViewIsBlank{
    CDVViewController* viewController = [self viewController];
    [viewController view];
    NSString* html = @"<html><body></body></html>";
    [viewController.webViewEngine loadHTMLString:html baseURL:@"about:blank"];
    XCTAssertTrue([viewController checkAndReinitViewUrl]);
    XCTAssertFalse([viewController checkAndReinitViewUrl]);
}

However, loadRequest does not load anything when running tests, and the url is always null..

Any chance you could take this PR from here and add the missing test? I suspect it should not be difficult, however might require some more background knowledge about cordova/ios..

I can also confirm that the approach to solve the initial problem (frozen apps for users) has been fixed by this PR (after also checking if it's not null and not "about:blank")

Thanks!

@shazron
Copy link
Member

shazron commented May 16, 2018

@svalaskevicius sure, will do. Can you make sure the checkbox "allow maintainers to make edits" is checked? Thanks: https://blog.github.com/2016-09-07-improving-collaboration-with-forks/

@shazron
Copy link
Member

shazron commented May 16, 2018

Never mind, I just did a push and it was successful. Looks like it was checked by default.

@shazron shazron changed the title reinit url after app freezes CB-14045 - reinit url after app freezes May 16, 2018
@shazron shazron merged commit 6b3f10f into apache:4.5.x May 16, 2018
shazron pushed a commit that referenced this pull request May 16, 2018
* test reinit url
* refactor: split function + check if appUrl is not empty
* Added tests.
shazron added a commit that referenced this pull request May 16, 2018
@shazron
Copy link
Member

shazron commented May 16, 2018

Made a mistake - didn't realize this was based off 4.5.x branch so it was pulled into that. Reverted the change to 4.5.x and applied to master instead.

@svalaskevicius
Copy link
Contributor Author

thanks!

@svalaskevicius svalaskevicius deleted the test-reinit-url branch May 16, 2018 09:34
@svalaskevicius svalaskevicius restored the test-reinit-url branch May 16, 2018 09:34
@GulinSS
Copy link

GulinSS commented Sep 6, 2018

Did it been added for current 4.5.5 public release?

brodybits pushed a commit to brodybits/cordova-ios that referenced this pull request Sep 27, 2018
* test reinit url
* refactor: split function + check if appUrl is not empty
* Added tests.
brodybits pushed a commit to brodybits/cordova-ios that referenced this pull request Sep 27, 2018
* test reinit url
* refactor: split function + check if appUrl is not empty
* Added tests.
@brodybits
Copy link
Contributor

Did it been added for current 4.5.5 public release?

No it was removed from 4.5.5 since we intended to merge the fix on master as discussed in #363 (comment). I just raised PR #418 in case we do another cordova-ios@4.5.x patch release.

As a general rule I recommend asking this kind of question in a new issue or by email to avoid losing such comments in closed issues and merged PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants