Hello,
I have created one LWC component where I'm using the registerRefreshHandler from 'lightning/refresh' to refresh my component automatically (instead of refreshing the whole page manually) which is called in connected callback.
But, the issue is sometimes, when I refresh the page manually, the page keeps on refreshing in recursive loop.
Below is my sample code:
connectedCallback(){
this.refreshHandlerID = registerRefreshHandler(this, this.refreshHandler);
this.loadInitialData();
}
refreshHandler(){
return new Promise((resolve) =>{
this.loadInitialData();
resolve(false);
})
}
loadInitialData(){
getRelatedCaseAndOrderStatus({ "recordId" : this.recordId})
.then(result => {
//logic
})
.catch(error => {
console.log(error);
})
}
disconnectedCallback() {
unregisterRefreshHandler(this.refreshHandlerID);
}
Can someone please help me why it is happening?
Also, one more point, the below setting was not enabled in my org for previous LWC component. I had to enable this because registerRefreshHandler does not work without enabling that setting and the component throws an error.
Session Setting --> Use Lightning Web Security for Lightning web components and Aura components