Fix errors in loading of help view (#1501)

When clicking on one of the cards from the home page of the docsite and
when initially loading the home page of the docsite, the webviewTag was
emitting a `did-frame-navigate` event, which we weren't tracking. This
meant that we were not properly recording that a navigation had
occurred. This caused three separate issues:

- We were never setting the meta url for the block, which meant that
when you navigated to a different tab or reloaded the app, you'd lose
what page you were last on.
- The site would reload after we fixed a broken docsite url, but we
wouldn't remove the error text that blocks the broken site.
- Clicking on the "open in external browser" button wouldn't do
anything.
This commit is contained in:
Evan Simkowitz 2024-12-11 16:09:47 -08:00 committed by GitHub
parent 98027204ca
commit 9ce0093751
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 7 deletions

View File

@ -54,6 +54,7 @@ class HelpViewModel extends WebViewModel {
const strippedDocsiteUrl = getApi().getDocsiteUrl().replace(baseUrlRegex, "");
const strippedCurUrl = url.replace(baseUrlRegex, "").replace(strippedDocsiteUrl, "");
const newUrl = docsiteWebUrl + strippedCurUrl;
console.log("modify-external-url", url, newUrl);
return newUrl;
};
}
@ -97,7 +98,6 @@ function HelpView({ model }: { model: HelpViewModel }) {
// Correct the base URL of the current page, if necessary
const newBaseUrl = baseUrlRegex.exec(newDocsiteUrl)?.[0];
const curBaseUrl = baseUrlRegex.exec(url)?.[0];
console.log("fix-docsite-url", url, newDocsiteUrl, homepageUrl, curBaseUrl, newBaseUrl);
if (curBaseUrl && newBaseUrl && curBaseUrl !== newBaseUrl) {
model.loadUrl(url.replace(curBaseUrl, newBaseUrl), "fix-fail-load");
}

View File

@ -142,6 +142,7 @@ export class WebViewModel implements ViewModel {
icon: "arrow-up-right-from-square",
title: "Open in External Browser",
click: () => {
console.log("open external", url);
if (url != null && url != "") {
const externalUrl = this.modifyExternalUrl?.(url) ?? url;
return getApi().openExternal(externalUrl);
@ -339,14 +340,14 @@ export class WebViewModel implements ViewModel {
const searchTemplate = globalStore.get(defaultSearchAtom);
const nextUrl = this.ensureUrlScheme(newUrl, searchTemplate);
console.log("webview loadUrl", reason, nextUrl, "cur=", this.webviewRef?.current.getURL());
if (newUrl != nextUrl) {
globalStore.set(this.url, nextUrl);
}
if (!this.webviewRef.current) {
return;
}
if (this.webviewRef.current.getURL() != nextUrl) {
this.webviewRef.current.loadURL(nextUrl);
fireAndForget(() => this.webviewRef.current.loadURL(nextUrl));
}
if (newUrl != nextUrl) {
globalStore.set(this.url, nextUrl);
}
}
@ -531,8 +532,8 @@ const WebView = memo(({ model, onFailLoad }: WebViewProps) => {
return;
}
const navigateListener = (e: any) => {
setErrorText("");
if (e.isMainFrame) {
setErrorText("");
model.handleNavigate(e.url);
}
};
@ -582,6 +583,7 @@ const WebView = memo(({ model, onFailLoad }: WebViewProps) => {
model.setMediaPlaying(false);
};
webview.addEventListener("did-frame-navigate", navigateListener);
webview.addEventListener("did-navigate-in-page", navigateListener);
webview.addEventListener("did-navigate", navigateListener);
webview.addEventListener("did-start-loading", startLoadingHandler);
@ -596,6 +598,7 @@ const WebView = memo(({ model, onFailLoad }: WebViewProps) => {
// Clean up event listeners on component unmount
return () => {
webview.removeEventListener("did-frame-navigate", navigateListener);
webview.removeEventListener("did-navigate", navigateListener);
webview.removeEventListener("did-navigate-in-page", navigateListener);
webview.removeEventListener("new-window", newWindowHandler);

View File

@ -145,7 +145,7 @@ func (svc *ObjectService) UpdateObjectMeta(uiContext waveobj.UIContext, orefStr
}
err = wstore.UpdateObjectMeta(ctx, *oref, meta, false)
if err != nil {
return nil, fmt.Errorf("error updateing %q meta: %w", orefStr, err)
return nil, fmt.Errorf("error updating %q meta: %w", orefStr, err)
}
return waveobj.ContextGetUpdatesRtn(ctx), nil
}