fix: Use alternative redirect method (#1176)

This commit is contained in:
Tom Moor
2020-02-16 17:28:24 -08:00
committed by GitHub
parent 71ed0844b9
commit 908b457dec

View File

@@ -1,6 +1,6 @@
// @flow // @flow
import * as React from 'react'; import * as React from 'react';
import { Redirect } from 'react-router-dom'; import { withRouter, type RouterHistory } from 'react-router-dom';
import { observable } from 'mobx'; import { observable } from 'mobx';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { lighten } from 'polished'; import { lighten } from 'polished';
@@ -20,6 +20,7 @@ type Props = {
readOnly?: boolean, readOnly?: boolean,
grow?: boolean, grow?: boolean,
disableEmbeds?: boolean, disableEmbeds?: boolean,
history: RouterHistory,
forwardedRef: React.Ref<RichMarkdownEditor>, forwardedRef: React.Ref<RichMarkdownEditor>,
ui: UiStore, ui: UiStore,
}; };
@@ -54,11 +55,7 @@ class Editor extends React.Component<Props> {
} }
} }
// protect against redirecting back to the same place this.props.history.push(navigateTo);
const currentLocation = window.location.pathname + window.location.hash;
if (currentLocation !== navigateTo) {
this.redirectTo = navigateTo;
}
} else { } else {
window.open(href, '_blank'); window.open(href, '_blank');
} }
@@ -85,8 +82,6 @@ class Editor extends React.Component<Props> {
}; };
render() { render() {
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
return ( return (
<React.Fragment> <React.Fragment>
<PrismStyles /> <PrismStyles />
@@ -285,7 +280,9 @@ const EditorTooltip = ({ children, ...props }) => (
</Tooltip> </Tooltip>
); );
export default withTheme( export default withRouter(
// $FlowIssue - https://github.com/facebook/flow/issues/6103 withTheme(
React.forwardRef((props, ref) => <Editor {...props} forwardedRef={ref} />) // $FlowIssue - https://github.com/facebook/flow/issues/6103
React.forwardRef((props, ref) => <Editor {...props} forwardedRef={ref} />)
)
); );