force full rerender/data refresh on unfreeze
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- react, typescript
- Ambito
- frontend, performance
Direzione di ricerca
Start with the Freeze component and the tab examples in the issue, then reproduce the behavior with the provided selectedTab and refresh patterns. Compare direct props with the ref-based approach and verify what happens when tabs freeze and unfreeze. Done means a tab can refetch calculated data on unfreeze without forcing unrelated tabs to rerender or breaking layout.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Apologies if this is a stupid question, but is there a way to essentially force some components to refresh/drop their data and fully rerender after unfreeze?
Scenario example.
I have a bunch of tabs, some of the tabs have live data so when they unfreeze they are up to date and all works great. But some of the tabs I want to always refetch their data as we either currently don't have a live update or it's not something that lends itself to live data. (eg some dashboard data that is caluclated on the backend and isn't live)
I've tried using a combination of freeze wrapped and non wrapped components in the tabs content, but this doesn't work well, either breaks layout or more often just causes the ones I do want to fully refresh to always fully rerender and refresh their data (I assume do to tree changing or something)
The below feels very hacky so would just like to know if there is a better/proper way to do this?
many thanks in advance.
what I've tried:
eg something like this doesn't seem to work and causes the freeze tabs to always fully rerender, I'm guessing as stack order has changed
<div class="tabcontent">
<Freeze freeze={'tab1' !== selectedTab} ><Tab1 /></Freeze>
<>{'tab2' === selectedTab && <Tab2 />}</>
<Freeze freeze={'tab3' !== selectedTab} ><Tab3 /></Freeze>
</div>
so I tried the following and using the freeze prop on tab2 to return null inside tab2 component when freeze true, that way the order of the child stack should be the same, but this totally screwed up all the layout
<div class="tabcontent">
<Freeze freeze={'tab1' !== selectedTab} ><Tab1 /></Freeze>
<Tab2 freeze={'tab2' !== selectedTab} />
<Freeze freeze={'tab3' !== selectedTab} ><Tab3 /></Freeze>
</div>
So the only way I've been able to make it work is to wrap freeze around everything and put a useEffect hack from a ref inside the components I want to cause their data to refretch. For some reason you have to use the ref for the comparison in the refresh property. if you use the state, it never changes inside the component.
const { selectedTab } = useContext(TabContext)
const selectedTabRef = useRef()
useEffect(() => {
selectedTabRef.current = selectedTab
}, [selectedTab, selectedTabRef])
<div class="tabcontent">
<Freeze freeze={'tab1' !== selectedTab} ><Tab1 /></Freeze>
<Freeze freeze={'tab2' !== selectedTab} ><Tab2 refresh={'tab2' !== selectedTabRef.current} /></Freeze>
<Freeze freeze={'tab3' !== selectedTab} ><Tab3 /></Freeze>
</div>
Heres the basic example of logic in tab2 to cause the refresh. What seems to happen is that when unfreezing this tab, selectedTabRef.current is still set to the previous tab, so refresh property is then set to true as it unfreezes. This only happens if comparing to a ref, if I compare directly to the selectedTab prop it never changes inside tab2
Tab2 gets that value (only when using the ref). This causes the useEffect to fire inside tab2. Once it's unfrozen, selectedTabRef.current has updated and ('tab2' !== selectedTabRef.current) = false so refresh prop inside tab2 is then also false.
const Tab2 = ({ refresh }) => {
const [refreshData, setRefreshData] = useState()
const [data, setData] = useState()
const fetchData = useCallback(() => {
...some code that fetches data and stores in data var
}, [])
useEffect(() => {
...some code that calls fetchdata on first render
}, [])
useEffect(() => {
if (refresh) {
if (!refreshData && data) {
setRefreshData(true)
fetchData()
}
return
}
if (refreshData) setRefreshData()
}, [refresh, refreshData, setRefreshData, fetchData, data])
}
- Lingua principale
- TypeScript
- Stelle
- 1.7k
- Fork
- 45
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di software-mansion/react-freeze
-
React 19.2: a frozen boundary is re-rendered and re-committed in a loop (retry lanes rotate forever), starving timers and network callbacksForse già presa @JacquesLeupin l’ha presa 12 giorni fa. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
software-mansion/react-freeze#44 · 1 commento · 1 reazione ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
software-mansion/react-freeze#38 · 6 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
software-mansion/react-freeze#35 · 1 commento · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
software-mansion/react-freeze#31 · 6 commenti · 1 reazione ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
software-mansion/react-freeze#30 · 1 commento ·
Tutte le issue di software-mansion/react-freeze
Issue simili
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
EPPIcenter/sampledb3#162 ·
-
Particle-1 modelAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
tashfeenahmed/freellmapi#2169 ·
I maintainer di solito rispondono entro 1 giorno
-
via-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
🎙️ task - feat(mechanic): pave git.pull.close, a close of a superseded pull with its why on recordAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ehmpathy/rhachet-roles-ehmpathy#1576 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
vercel-labs/ui#1563 ·
I maintainer di solito rispondono entro 1 giorno