From 1231a13478fe0b052ffc30e2a3e35edb80387f3b Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 15 Feb 2024 23:24:56 -0500 Subject: [PATCH] get rid of session refresh bug --- packages/fakeyou.com/src/App.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/fakeyou.com/src/App.tsx b/packages/fakeyou.com/src/App.tsx index 7307cefdbe..4090cabb0f 100644 --- a/packages/fakeyou.com/src/App.tsx +++ b/packages/fakeyou.com/src/App.tsx @@ -299,6 +299,8 @@ class App extends React.Component { await this.querySessionSubscriptions(); setInterval(async () => { + // See warnings in the following methods when adding new methods + // that affect global "state" await this.querySession(); await this.querySessionSubscriptions(); }, 60000); @@ -309,6 +311,10 @@ class App extends React.Component { } querySession = async () => { + // WARNING: Making setState calls in this scope without checking existing + // state can cause the whole site to refresh/worsen UX. Double check if + // state needs to be set here, or if instead can be refreshed locally on + // the page where the new "state" needed const sessionWrapper = await SessionWrapper.lookupSession(); const username = sessionWrapper.getDisplayName(); const cookies = new Cookies(); @@ -336,7 +342,15 @@ class App extends React.Component { }; querySessionSubscriptions = async () => { - this.setState({ sessionFetched: true }); + // WARNING: Making setState calls in this scope without checking existing + // state can cause the whole site to refresh/worsen UX. Double check if + // state needs to be set here, or if instead can be refreshed locally on + // the page where the new "state" needed + + if (this.state.sessionFetched === false){ + this.setState({ sessionFetched: true }); + } + const cookies = new Cookies(); const sessionSubscriptionsWrapper =