-
Notifications
You must be signed in to change notification settings - Fork 987
fix: ensure signing out cannot cause any runtime render errors #13137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4da94ef
fix: remove some of the jank around our core App component
Parkreiner 9986024
refactor: scope navigation logic more aggressively
Parkreiner 7004c9c
refactor: add explicit return type to useAuthenticated
Parkreiner ebfaec5
refactor: clean up ProxyContext code
Parkreiner 1192eb3
wip: add code for consolidating the HTML metadata
Parkreiner bbe2ae0
refactor: clean up hook logic
Parkreiner 1c41937
refactor: rename useHtmlMetadata to useEmbeddedMetadata
Parkreiner 79e9c45
fix: correct names that weren't updated
Parkreiner 81f2cd9
fix: update type-safety of useEmbeddedMetadata further
Parkreiner 390418f
wip: switch codebase to use metadata hook
Parkreiner 486f292
Merge branch 'main' into mes/login-fix
Parkreiner b77af73
Merge branch 'mes/login-fix' of https://github.com/coder/coder into m…
Parkreiner e072f7a
refactor: simplify design of metadata hook
Parkreiner 2a58322
fix: update stray type mismatches
Parkreiner b55abb7
fix: more type fixing
Parkreiner c45e1b7
fix: resolve illegal invocation error
Parkreiner 2a63c1d
fix: get metadata issue resolved
Parkreiner 4d3b155
fix: update comments
Parkreiner 8067e77
chore: add unit tests for MetadataManager
Parkreiner 5e6e974
fix: beef up tests
Parkreiner 772b96f
fix: update typo in tests
Parkreiner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import { getWorkspaceProxies, getWorkspaceProxyRegions } from "api/api"; | |
import { cachedQuery } from "api/queries/util"; | ||
import type { Region, WorkspaceProxy } from "api/typesGenerated"; | ||
import { useAuthenticated } from "contexts/auth/RequireAuth"; | ||
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata"; | ||
import { type ProxyLatencyReport, useProxyLatency } from "./useProxyLatency"; | ||
|
||
export interface ProxyContextValue { | ||
|
@@ -94,37 +95,8 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => { | |
computeUsableURLS(userSavedProxy), | ||
); | ||
|
||
const queryKey = ["get-proxies"]; | ||
// This doesn't seem like an idiomatic way to get react-query to use the | ||
// initial data without performing an API request on mount, but it works. | ||
// | ||
// If anyone would like to clean this up in the future, it should seed data | ||
// from the `meta` tag if it exists, and not fetch the regions route. | ||
const [initialData] = useState(() => { | ||
// Build info is injected by the Coder server into the HTML document. | ||
const regions = document.querySelector("meta[property=regions]"); | ||
if (regions) { | ||
const rawContent = regions.getAttribute("content"); | ||
try { | ||
const obj = JSON.parse(rawContent as string); | ||
if ("regions" in obj) { | ||
return obj.regions as Region[]; | ||
} | ||
return obj as Region[]; | ||
} catch (ex) { | ||
// Ignore this and fetch as normal! | ||
} | ||
} | ||
}); | ||
|
||
const { permissions } = useAuthenticated(); | ||
const query = async (): Promise<readonly Region[]> => { | ||
const endpoint = permissions.editWorkspaceProxies | ||
? getWorkspaceProxies | ||
: getWorkspaceProxyRegions; | ||
const resp = await endpoint(); | ||
return resp.regions; | ||
}; | ||
const { metadata } = useEmbeddedMetadata(); | ||
|
||
const { | ||
data: proxiesResp, | ||
|
@@ -133,9 +105,15 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => { | |
isFetched: proxiesFetched, | ||
} = useQuery( | ||
cachedQuery({ | ||
initialData, | ||
queryKey, | ||
queryFn: query, | ||
metadata: metadata.regions, | ||
queryKey: ["get-proxies"], | ||
queryFn: async (): Promise<readonly Region[]> => { | ||
const endpoint = permissions.editWorkspaceProxies | ||
? getWorkspaceProxies | ||
: getWorkspaceProxyRegions; | ||
const resp = await endpoint(); | ||
return resp.regions; | ||
}, | ||
Comment on lines
+108
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just inlined a bunch of the values, since they're only used here |
||
}), | ||
); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Emyrk I wasn't completely sure why we had a check for whether the data getting parsed was either an array or an object with the array inside it, but just to be on the safe side, I ripped this out and centralized it in the metadata manager file
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question. The type safety we have on these fields is terrible, and should be resolved imo to make things like this more clear. We just inject strings that are json. Very weak imo.
I'll dig a bit and find out