Skip to content
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

Remove useEffect from LinkView to ensure the logic runs before render #6464

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/volto/news/6464.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed LinkView logged-in page flashing on screen when not logged in. @JeffersonBledsoe
30 changes: 11 additions & 19 deletions packages/volto/src/components/theme/View/LinkView.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
import { useEffect } from 'react';
import PropTypes from 'prop-types';
import { useHistory } from 'react-router-dom';
import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers';
import { Container as SemanticContainer } from 'semantic-ui-react';
import { UniversalLink } from '@plone/volto/components';
import { Redirect } from 'react-router-dom';
import { FormattedMessage } from 'react-intl';
import { flattenToAppURL, isInternalURL } from '@plone/volto/helpers';
import config from '@plone/volto/registry';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { Redirect } from 'react-router-dom';
import { Container as SemanticContainer } from 'semantic-ui-react';

const LinkView = ({ token, content }) => {
const history = useHistory();
useEffect(() => {
if (!token) {
const { remoteUrl } = content;
if (isInternalURL(remoteUrl)) {
history.replace(flattenToAppURL(remoteUrl));
} else if (!__SERVER__) {
window.location.href = flattenToAppURL(remoteUrl);
}
if (!token && content.remoteUrl) {
// React router can handle all redirects except for client-side to an external URL.
if (isInternalURL(content.remoteUrl) || __SERVER__) {
return <Redirect to={flattenToAppURL(content.remoteUrl)} />;
}
}, [content, history, token]);
if (__SERVER__ && !token && content.remoteUrl) {
Copy link
Member

Choose a reason for hiding this comment

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

@JeffersonBledsoe Are you sure this will not raise an error on SSR 🤔 ?!

return <Redirect to={content.remoteUrl} />;
window.location.href = content.remoteUrl;
return null;
}
const { title, description, remoteUrl } = content;
const { openExternalLinkInNewTab } = config.settings;
Expand Down