-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Iterate on ApiProxy to keep login/logout message off the Messag…
…eChannel (#142) Related to: getsentry/sentry#81942 Changes: - The `request-login` and `request-logout` messages are going over `iframe.contentWindow.postMessage()` now. The MessagePort is reserved for when the iframe is logged in and properly configured. - When state _changes_ we dispose of any ports (would only been connected if we were previously logged in) and reload the iframe. This ensures that we get a new state told to us from the html file - We've dropped the `sentryApiPath` config value, because the config endpoint (domain, region if needed, and this prefix) is set inside the iframe js scripts. The `fetch` command of the proxy can only make fetch requests to the sentry api now, not to other domains.
- Loading branch information
Showing
17 changed files
with
159 additions
and
146 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {renderHook} from '@testing-library/react'; | ||
import usePrevious from 'toolbar/hooks/usePrevious'; | ||
|
||
describe('usePrevious', () => { | ||
it('stores initial value', () => { | ||
const {result} = renderHook(usePrevious, {initialProps: 'Initial Value'}); | ||
expect(result.current).toBe('Initial Value'); | ||
}); | ||
|
||
it('provides initial value', () => { | ||
const {result} = renderHook(usePrevious, { | ||
initialProps: 'Initial Value', | ||
}); | ||
|
||
expect(result.current).toBe('Initial Value'); | ||
}); | ||
|
||
it('provides previous value', () => { | ||
const {result, rerender} = renderHook(usePrevious<string | undefined>, { | ||
initialProps: undefined, | ||
}); | ||
|
||
rerender('New Value'); | ||
// We did not pass anything under initialProps | ||
expect(result.current).toBe(undefined); | ||
rerender('New New Value'); | ||
// Result should point to old value | ||
expect(result.current).toBe('New Value'); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {useEffect, useRef} from 'react'; | ||
|
||
/** | ||
* Provides previous prop or state inside of function components. | ||
* It’s possible that in the future React will provide a usePrevious Hook out of the box since it’s a relatively common use case. | ||
* @see {@link https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state} | ||
* | ||
* @returns 'ref.current' and therefore should not be used as a dependency of useEffect. | ||
* Mutable values like 'ref.current' are not valid dependencies of useEffect because changing them does not re-render the component. | ||
*/ | ||
function usePrevious<T>(value: T): T { | ||
// The ref object is a generic container whose current property is mutable ... | ||
// ... and can hold any value, similar to an instance property on a class | ||
const ref = useRef<T>(value); | ||
// Store current value in ref | ||
useEffect(() => { | ||
ref.current = value; | ||
}, [value]); // Only re-run if value changes | ||
// Return previous value (happens before update in useEffect above) | ||
return ref.current; | ||
} | ||
|
||
export default usePrevious; |
This file contains 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 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 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
Oops, something went wrong.