formidable-webview / webshell

🔥 Craft Robust React Native WebView-based components with ease.
https://formidable-webview.github.io/webshell/
MIT License
102 stars 4 forks source link

web script errors/warnings #4

Closed z0al closed 3 years ago

z0al commented 3 years ago

Description

Everything is working as expected but I still get these errors/warnings and I'm not sure if I can do something about them. Especially since they happen randomly.

[Webshell]: Web script from feature "org.formidable-webview/webshell.handle-html-dimensions" raised an error: Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element'.
- node_modules/react-native/Libraries/LogBox/LogBox.js:117:10 in registerWarning
- node_modules/react-native/Libraries/LogBox/LogBox.js:63:8 in warnImpl
- node_modules/react-native/Libraries/LogBox/LogBox.js:36:4 in console.warn
- node_modules/expo/build/environment/react-native-logs.fx.js:18:4 in warn
- node_modules/@formidable-webview/webshell/lib/commonjs/Reporter.js:158:13 in dispatchError
- node_modules/@formidable-webview/webshell/lib/commonjs/hooks/useWebshell.js:116:15 in React.useCallback$argument_0
- node_modules/react-native-webview/lib/WebView.android.js:203:16 in _this.onMessage
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

[Webshell]: Web script from feature "org.formidable-webview/webshell.force-responsive-viewport" raised an error: Cannot read property 'appendChild' of null
- node_modules/react-native/Libraries/LogBox/LogBox.js:117:10 in registerWarning
- node_modules/react-native/Libraries/LogBox/LogBox.js:63:8 in warnImpl
- node_modules/react-native/Libraries/LogBox/LogBox.js:36:4 in console.warn
- node_modules/expo/build/environment/react-native-logs.fx.js:18:4 in warn
- node_modules/@formidable-webview/webshell/lib/commonjs/Reporter.js:158:13 in dispatchError
- node_modules/@formidable-webview/webshell/lib/commonjs/hooks/useWebshell.js:116:15 in React.useCallback$argument_0
- node_modules/react-native-webview/lib/WebView.android.js:203:16 in _this.onMessage
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

Environment

"@formidable-webview/webshell": "^2.2.0"
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz"
"react-native-webview": "11.0.0"

Example

I literally copy-pasted the example from Autoheight WebView

Show code anyway ```javascript import makeWebshell, { HandleHashChangeFeature, HandleHTMLDimensionsFeature, useAutoheight } from '@formidable-webview/webshell'; import type { HashChangeEvent } from '@formidable-webview/webshell'; import React, { useCallback, useRef, useState } from 'react'; import { LayoutChangeEvent, ScrollView, StyleSheet, View } from 'react-native'; import WebView from 'react-native-webview'; const Webshell = makeWebshell( WebView, new HandleHTMLDimensionsFeature(), new HandleHashChangeFeature({ shouldResetHashOnEvent: true }), new shell.ForceElementSizeFeature({ target: 'body', heightValue: 'auto', widthValue: 'auto', }), new shell.ForceResponsiveViewportFeature({ maxScale: 1, }) ); export const AutoheightWebViewInScrollView = ( webshellProps ) => { const scrollViewRef = useRef(null); const { autoheightWebshellProps } = useAutoheight({ webshellProps }); const [spaceTop, setSpaceTop] = useState(0); const onLayout = useCallback( (e: LayoutChangeEvent) => setSpaceTop(e.nativeEvent.layout.y), [] ); const onDOMHashChange = useCallback( (e: HashChangeEvent) => { scrollViewRef.current?.scrollTo({ y: e.targetElementBoundingRect.top + spaceTop, animated: true }); }, [spaceTop] ); return ( ); }; const styles = StyleSheet.create({ viewBeforeWebView: { height: 50, alignSelf: 'stretch' }, scrollView: { flex: 1 } }); ```

I'm loading a static HTML string but I don't think posting the actual string would be of any value since the issue happens randomly with different strings.

P.S. Thank you so much for this awesome library!

jsamr commented 3 years ago

@z0a Thanks a lot for your report! I guess I'm missing a major detail: on which platform this issue is raised? Also, please provide the version of the operating system affected. It would also be helpful to have the webpage concerned by this issue. My first guess would be that would happen when the loaded page is "blank", and thus some variables in the DOM are null. But better investigate with more evidence. Thanks!

z0al commented 3 years ago

I guess I'm missing a major detail: on which platform this issue is raised? Also, please provide the version of the operating system affected

Pixel 4 XL (API 30) simulator (On Ubuntu 20.04) - Android 11.0

My first guess would be that would happen when the loaded page is "blank"

That's actually correct. I load the HTML string from a local SQLite DB when the screen is mounted. Loading from SQLite is quite fast but I guess sometimes it takes long enough for the Page to be first loaded "blank" because of the way it's called:

<WebView source={{html: data?.content || '' }} />

What if I instead pass a string with an empty body. Does it also count as "blank"?

<html>
  <head></head>
  <body></body>
</html>

Ofc, I could also conditionally render the WebView when the data is not ready but I would rather have the WebView already mounted and ready to speed the overall process.

jsamr commented 3 years ago

@z0al I would try the empty body snippet when data is empty, because some features rely on the assumption that there is a body. I guess that I could fix those scripts to avoid such nuisance! Please try this, and if indeed the error disappear, I will amend those scripts.

z0al commented 3 years ago

Unfortunately, that doesn't seem to be the case.

I tried always setting the source HTML to '' and that didn't trigger any error no matter how many times I try. Setting the HTML source to always be <html><head></head><body></body></head> has the same effect too.

I now think the errors only appear on a few specific HTML strings (again, randomly). I will try to investigate this more later to come up with a minimal reproducible example.

jsamr commented 3 years ago

@z0al Thanks for your feedback. Yes, once I can reproduce the issue easily, I'll be able to investigate efficiently!

jsamr commented 3 years ago

@z0al Do you think could try out the new release 2.3.0 and tell me if the issue still occurs?

z0al commented 3 years ago

I can confirm that I don't see these errors anymore. Thank you @jsamr

sonnguyen2000-github commented 3 years ago

Warning

 [Webshell]: Web script from feature "org.formidable-webview/webshell.handle-html-dimensions" raised an error: Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element' 

still randomly occurs on version ^2.5.0