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

Fix dom not ready crashing the app #614

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

abhiroopc84
Copy link
Contributor

Description

Fix an issue where the app was crashing when an element tries to call a method that requires the dom-ready event to be emitted before.

What is the purpose of this pull request?

  • New feature
  • Documentation update
  • Bug fix
  • Refactor
  • Release
  • Other

Copy link
Contributor

@Kitenite Kitenite left a comment

Choose a reason for hiding this comment

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

I don't think this would be the case. The reference itself is non-null. The instance it references may be null. But it seems more of an issue due to the electron webview instance not loading a DOM yet. Has #612 failed to fix the issue?

@abhiroopc84
Copy link
Contributor Author

#612 did fix the issue, but I just thought adding two additional try catch blocks just to catch those errors would be redundant when we can just have a state domReady that is a boolean value which we'll use to either pass the webviewRef when dom has loaded, or null when dom hasn't loaded yet, to the BrowserControl component. domReady state can be set to true when we run the existing handleDomReady function. This way we'll be fixing the issue in the same component where the webviewRef is defined originally, so we can always use the same fix even if we face a similar error in some other component instead of adding try catch blocks in each such error component.

Copy link
Contributor

@Kitenite Kitenite left a comment

Choose a reason for hiding this comment

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

I like this. It adds just a bit of complexity but it's better than my duct tape solution. Well done!

@@ -119,7 +121,7 @@ const Frame = observer(
return (
<div className="flex flex-col space-y-4">
<BrowserControls
webviewRef={webviewRef}
webviewRef={domReady ? webviewRef : null}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see what you did. Apologies, I missed this. This makes sense and adds a level of security. I'd hate to have an error thrown needlessly.

@Kitenite Kitenite merged commit d601877 into onlook-dev:main Oct 22, 2024
@abhiroopc84 abhiroopc84 deleted the bugs/fix-webview-dom-not-ready branch October 26, 2024 07:45
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.

2 participants