fix url navigation (#353)

This commit is contained in:
Mike Sawka 2024-09-07 18:22:13 -07:00 committed by GitHub
parent 5e80aeb22a
commit f62d96ae99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -177,7 +177,7 @@ export class WebViewModel implements ViewModel {
const waveEvent = adaptFromReactOrNativeKeyEvent(event); const waveEvent = adaptFromReactOrNativeKeyEvent(event);
if (checkKeyPressed(waveEvent, "Enter")) { if (checkKeyPressed(waveEvent, "Enter")) {
const url = globalStore.get(this.url); const url = globalStore.get(this.url);
this.loadUrl(url); this.loadUrl(url, "enter");
this.urlInputRef.current?.blur(); this.urlInputRef.current?.blur();
return; return;
} }
@ -254,14 +254,17 @@ export class WebViewModel implements ViewModel {
* Load a new URL in the webview. * Load a new URL in the webview.
* @param newUrl The new URL to load in the webview. * @param newUrl The new URL to load in the webview.
*/ */
loadUrl(newUrl: string) { loadUrl(newUrl: string, reason: string) {
console.log("loadUrl", newUrl);
const nextUrl = this.ensureUrlScheme(newUrl); const nextUrl = this.ensureUrlScheme(newUrl);
const normalizedNextUrl = this.normalizeUrl(nextUrl); console.log("webview loadUrl", reason, nextUrl, "cur=", this.webviewRef?.current.getURL());
const normalizedCurUrl = this.normalizeUrl(globalStore.get(this.url)); if (newUrl != nextUrl) {
globalStore.set(this.url, nextUrl);
if (normalizedCurUrl !== normalizedNextUrl) { }
this.webviewRef?.current.loadURL(normalizedNextUrl); if (!this.webviewRef.current) {
return;
}
if (this.webviewRef.current.getURL() != nextUrl) {
this.webviewRef.current.loadURL(nextUrl);
} }
} }
@ -345,7 +348,7 @@ const WebView = memo(({ model }: WebViewProps) => {
useEffect(() => { useEffect(() => {
if (metaUrlRef.current != metaUrl) { if (metaUrlRef.current != metaUrl) {
metaUrlRef.current = metaUrl; metaUrlRef.current = metaUrl;
model.loadUrl(metaUrl); model.loadUrl(metaUrl, "meta");
} }
}, [metaUrl]); }, [metaUrl]);