Skip to content

fix refresh crashing app - #4296

Closed
zanesq wants to merge 5 commits into
mainfrom
zane/fix-refresh
Closed

fix refresh crashing app#4296
zanesq wants to merge 5 commits into
mainfrom
zane/fix-refresh

Conversation

@zanesq

@zanesq zanesq commented Aug 22, 2025

Copy link
Copy Markdown
Contributor

Made the fallbacks for checking local storage more resilient. Also added a backup mechanism for navigation since electron can have issues with hash based routing on load.

  • added exponential backoff retries to avoid accessing local storage before its available
  • added direct call to react router navigation with fallback to hash routing to avoid protocol errors in electron

fixes #4255

@zanesq
zanesq requested review from DOsinga and alexhancock August 22, 2025 20:06
Comment thread ui/desktop/src/App.tsx
break;

// Use React Router navigation if available, otherwise fallback to hash manipulation
if (navigateRef.current) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When is it not available?

Comment thread ui/desktop/src/main.ts Outdated
@@ -659,25 +659,42 @@ const createChat = async (
.executeJavaScript(
`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A bit outside the scope of this PR, but why do we need to manually call executeJavaScript on this block?

Could we not move it to some renderer side ts?

@zanesq

zanesq commented Aug 25, 2025

Copy link
Copy Markdown
Contributor Author

@alexhancock I can see how this would be confusing so I added comments to both of these. Let me know if it makes sense or not.

zanesq added 2 commits August 25, 2025 10:07
* 'main' of github.com:block/goose:
  fix slow typing with long sessions (#4291)
  docs: improvements to release docs (#4317)
  blog: mcp-ui recap blog (#4146)
  added more logging for recipe creation failures (#4299)
  Remove a bit from pre-commit that husky says we should (#4286)
  feat: autovisualiser of structured data with mcp-ui (#4153)
  docs: Plan tutorial (#4309)
  Extensions Modal Improvements (#4293)
  docs: fixed cicd tutorial pipeline in docs (#4223)
  Read oltp config from config and env (#4292)

# Conflicts:
#	ui/desktop/src/App.tsx

@DOsinga DOsinga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we should maybe discuss this some more, this does feel like we're trying to fix stuff on top of shaky stuff maybe?

Comment thread ui/desktop/src/App.tsx
onNavigateReady={(navigate) => {
navigateRef.current = navigate;
}}
/>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you'll have to explain to me why we need this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Basically setView was being called before react router was ready during direct navigation or refresh so now it will capture it and use it once its ready. We prefer to use react router navigation anyway so it should improve things. That being said I can leave this part out for now and only do the local storage changes to see if that is enough to fix the refresh issue.

Comment thread ui/desktop/src/main.ts
const injectionScript = localStorageInjectionScript('gooseConfig', configStr);
mainWindow.webContents.executeJavaScript(injectionScript).catch((error) => {
console.error('Failed to execute localStorage script:', error);
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why again do we want this to be injected into local storage? we seem to be loading this with:

  getConfig: () => {
    // Add fallback to localStorage if config from preload is empty or missing
    if (!config || Object.keys(config).length === 0) {
      try {
        if (window.localStorage) {
          const storedConfig = localStorage.getItem('gooseConfig');
          if (storedConfig) {
            return JSON.parse(storedConfig);
          }
        }
      } catch (e) {
        console.warn('Failed to parse stored config from localStorage:', e);
      }
    }
    return config;

couldn't we store it locally in the renderer and when it can't be found just do an ipc call back to the electron processs? or expose it using exposeInMainWorld that I just learned about?

@zanesq zanesq Aug 25, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed this can probably be improved with some exposeInMainWorld logic but unfortunately would require more time so I think we should come back to that in a bigger refactor. IPC would require async calls that happen further down the chain and could cause race conditions. This is just a way to get it called as early as possible and have retries to fix the main error that localstorage isn't available to the browser yet when it tries to access it.

As for why we put config in local storage I'm guessing its so it can be loaded faster from multiple windows but it may be a legacy thing that we could come back to and remove also.

@zanesq

zanesq commented Aug 26, 2025

Copy link
Copy Markdown
Contributor Author

Appreciate the feedback! Closing this in favor of a more targeted fix #4355

@zanesq zanesq closed this Aug 26, 2025
@DOsinga
DOsinga deleted the zane/fix-refresh branch May 14, 2026 19:37
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.

Reload Doesn't Work

3 participants