From 7e7ca52cca8e3cdbb630f26e0b5ab0611578a620 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 31 Jan 2022 10:49:51 -0600 Subject: [PATCH 1/3] Delay rendering until instance has loaded or failed (for feature detection) --- app/soapbox/containers/soapbox.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/soapbox/containers/soapbox.js b/app/soapbox/containers/soapbox.js index 40b4e10b6..23c0a84bd 100644 --- a/app/soapbox/containers/soapbox.js +++ b/app/soapbox/containers/soapbox.js @@ -31,6 +31,14 @@ import configureStore from '../store/configureStore'; const validLocale = locale => Object.keys(messages).includes(locale); +// Delay rendering until instance has loaded or failed (for feature detection) +const isInstanceLoaded = state => { + const v = state.getIn(['instance', 'version']); + const fetchFailed = state.getIn(['meta', 'instance_fetch_failed'], false); + + return v !== '0.0.0' || fetchFailed; +}; + export const store = configureStore(); // Configure global functions for developers @@ -60,6 +68,7 @@ const mapStateToProps = (state) => { return { showIntroduction, me, + instanceLoaded: isInstanceLoaded(state), reduceMotion: settings.get('reduceMotion'), underlineLinks: settings.get('underlineLinks'), systemFont: settings.get('systemFont'), @@ -80,6 +89,7 @@ class SoapboxMount extends React.PureComponent { static propTypes = { showIntroduction: PropTypes.bool, me: SoapboxPropTypes.me, + instanceLoaded: PropTypes.bool, reduceMotion: PropTypes.bool, underlineLinks: PropTypes.bool, systemFont: PropTypes.bool, @@ -124,8 +134,9 @@ class SoapboxMount extends React.PureComponent { } render() { - const { me, themeCss, locale, customCss } = this.props; + const { me, instanceLoaded, themeCss, locale, customCss } = this.props; if (me === null) return null; + if (!instanceLoaded) return null; if (this.state.localeLoading) return null; // Disabling introduction for launch From 6e889c7a4f3ca17c03a5049e5ad13798ab98f60d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 31 Jan 2022 11:18:44 -0600 Subject: [PATCH 2/3] Mastodon: fall back to account lookup API --- app/soapbox/actions/accounts.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/soapbox/actions/accounts.js b/app/soapbox/actions/accounts.js index aacdcd106..fe0f5519a 100644 --- a/app/soapbox/actions/accounts.js +++ b/app/soapbox/actions/accounts.js @@ -156,14 +156,7 @@ export function fetchAccountByUsername(username) { const features = getFeatures(instance); const me = state.get('me'); - if (!me && features.accountLookup) { - dispatch(accountLookup(username)).then(account => { - dispatch(fetchAccountSuccess(account)); - }).catch(error => { - dispatch(fetchAccountFail(null, error)); - dispatch(importErrorWhileFetchingAccountByUsername(username)); - }); - } else if (features.accountByUsername) { + if (features.accountByUsername && (me || !features.accountLookup)) { api(getState).get(`/api/v1/accounts/${username}`).then(response => { dispatch(fetchRelationships([response.data.id])); dispatch(importFetchedAccount(response.data)); @@ -172,6 +165,13 @@ export function fetchAccountByUsername(username) { dispatch(fetchAccountFail(null, error)); dispatch(importErrorWhileFetchingAccountByUsername(username)); }); + } else if (features.accountLookup) { + dispatch(accountLookup(username)).then(account => { + dispatch(fetchAccountSuccess(account)); + }).catch(error => { + dispatch(fetchAccountFail(null, error)); + dispatch(importErrorWhileFetchingAccountByUsername(username)); + }); } else { dispatch(accountSearch({ q: username, From 0d000bf4e00818c8a4277e1e8eb1ec8b864cc868 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 31 Jan 2022 11:23:39 -0600 Subject: [PATCH 3/3] Set instance version default, just in case... --- app/soapbox/containers/soapbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/containers/soapbox.js b/app/soapbox/containers/soapbox.js index 23c0a84bd..301de4c01 100644 --- a/app/soapbox/containers/soapbox.js +++ b/app/soapbox/containers/soapbox.js @@ -33,7 +33,7 @@ const validLocale = locale => Object.keys(messages).includes(locale); // Delay rendering until instance has loaded or failed (for feature detection) const isInstanceLoaded = state => { - const v = state.getIn(['instance', 'version']); + const v = state.getIn(['instance', 'version'], '0.0.0'); const fetchFailed = state.getIn(['meta', 'instance_fetch_failed'], false); return v !== '0.0.0' || fetchFailed;