Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(api): UI crash with TypeError: i.map is not a function #6985

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

psychedelicious
Copy link
Collaborator

@psychedelicious psychedelicious commented Sep 30, 2024

Summary

This pops up every now and then and I could never figure it out. A user figured it out in #6936. The cause is appending a query string to the app URL.

For example:

http://127.0.0.1:9090/?__theme=dark

The query string breaking the static file serving, which prevents our translations from loading correctly. Instead of the JSON translations, FastAPI sends the index HTML page. The UI then errors when attempting to parse the translation JSON.

The query string ?__theme=dark is used by Gradio to force dark mode. I believe the users with this issue are doing the same thing the user in #6936 did (just change the port number on an existing bookmark) or their browser history/bookmark includes the query string.

Though this is technically a user-caused problem (we cannot prevent the user from using a malformed URL), we can work around it. When query string is used on the root path, we can redirect the browser to the root path without the query string.

This is done via very simple middleware.

Related Issues / Discussions

Closes #6696
Closes #6817
Closes #6828
Closes #6936
Closes #6983

QA Instructions

Do a prod build of the UI and navigate to http://127.0.0.1:9090/?__theme=dark

On main, we expect the UI to error. On this PR, we expect to be redirected to http://127.0.0.1:9090/ and not error.

Merge Plan

n/a

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • Documentation added / updated (if applicable)

This pops up every now and then and I could never figure it out. A user figured it out in #6936. The cause is appending a query string to the app URL.

For example:
```sh
http://127.0.0.1:9090/?__theme=dark
```

The query string breaking the static file serving, which prevents our translations from loading correctly. Instead of the JSON translations, FastAPI sends the index HTML page. The UI then errors when attempting to parse the translation JSON.

The query string ?__theme=dark is used by Gradio to force dark mode. I believe the users with this issue are doing the same thing the user in #6936 did (just change the port number on an existing bookmark) or their browser history/bookmark includes the query string.

Though this is technically a user-caused problem (we cannot prevent the user from using a malformed URL), we can work around it. When query string is used on the root path, we can redirect the browser to the root path without the query string.

This is done via very simple middleware.

Closes #6696
Closes #6817
Closes #6828
Closes #6936
Closes #6983
@psychedelicious psychedelicious force-pushed the psyche/fix/api/redirect-query-strings branch from 53a4c29 to 0e4d570 Compare September 30, 2024 02:49
@psychedelicious psychedelicious merged commit 21017ed into main Sep 30, 2024
14 checks passed
@psychedelicious psychedelicious deleted the psyche/fix/api/redirect-query-strings branch September 30, 2024 03:15
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
python PRs that change python files
Projects
None yet
2 participants