mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
Fixed WebView race condition
This commit is contained in:
parent
1e0d2b7b86
commit
66059939a3
@ -100,7 +100,7 @@ export default function NoteBodyViewer(props:Props) {
|
||||
injectedJavaScript={injectedJs.join('\n')}
|
||||
originWhitelist={['file://*', './*', 'http://*', 'https://*']}
|
||||
mixedContentMode="always"
|
||||
allowFileAccess={true} // TODO: Implement logic to avoid race condition between source and allowFileAccess
|
||||
allowFileAccess={true}
|
||||
onLoadEnd={onLoadEnd}
|
||||
onError={onError}
|
||||
onMessage={onMessage}
|
||||
|
@ -27,6 +27,7 @@ export default function useSource(noteBody:string, noteMarkupLanguage:number, th
|
||||
const [source, setSource] = useState<Source>(undefined);
|
||||
const [injectedJs, setInjectedJs] = useState<string[]>([]);
|
||||
const [resourceLoadedTime, setResourceLoadedTime] = useState(0);
|
||||
const [isFirstRender, setIsFirstRender] = useState(true);
|
||||
|
||||
const rendererTheme = useMemo(() => {
|
||||
return {
|
||||
@ -141,12 +142,24 @@ export default function useSource(noteBody:string, noteMarkupLanguage:number, th
|
||||
setInjectedJs(js);
|
||||
}
|
||||
|
||||
renderNote();
|
||||
// When mounted, we need to render the webview in two stages;
|
||||
// - First without any source, so that all webview props are setup properly
|
||||
// - Secondly with the source to actually render the note
|
||||
// This is necessary to prevent a race condition that could cause an ERR_ACCESS_DENIED error
|
||||
// https://github.com/react-native-webview/react-native-webview/issues/656#issuecomment-551312436
|
||||
|
||||
if (isFirstRender) {
|
||||
setIsFirstRender(false);
|
||||
setSource(undefined);
|
||||
setInjectedJs([]);
|
||||
} else {
|
||||
renderNote();
|
||||
}
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
}
|
||||
}, [resourceLoadedTime, noteBody, noteMarkupLanguage, themeId, rendererTheme, highlightedKeywords, noteResources, noteHash]);
|
||||
}, [resourceLoadedTime, noteBody, noteMarkupLanguage, themeId, rendererTheme, highlightedKeywords, noteResources, noteHash, isFirstRender]);
|
||||
|
||||
return { source, injectedJs };
|
||||
}
|
@ -1035,6 +1035,9 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||
bodyComponent = this.useBetaEditor()
|
||||
// Note: blurOnSubmit is necessary to get multiline to work.
|
||||
// See https://github.com/facebook/react-native/issues/12717#issuecomment-327001997
|
||||
//
|
||||
// 2020-10-16: As of React Native 0.63, the Markdown Editor no longer crashes in Android, however the
|
||||
// cursor is still too unreliable to be usable, so we disable it in Android.
|
||||
? <MarkdownEditor
|
||||
ref={this.markdownEditorRef} // For focusing the Markdown editor
|
||||
editorFont={editorFont(this.props.editorFont)}
|
||||
|
Loading…
Reference in New Issue
Block a user