You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This exception is handled but nevertheless it would be good to prevent it from happening at all. It happens sometimes when you navigate back from Reddit thread back to subreddit page.
exportconsthandleScrollDom=async()=>{if(!isActiveTabAndRedditThread())return;constcommentElements=document.querySelectorAll<HTMLElement>(commentSelector);if(!(commentElements.length>0))return;try{awaithighlightByDateWithSettingsData(commentElements);// this line throws itawaitdelayExecution(markAsRead,markAsReadDelay,commentElements);if(!isActiveTabAndRedditThread())return;awaithighlight(commentElements);}catch(error){logger.error('Error handling comments onScroll:',error);}};
constgetTimestampIdFromCommentId=(commentId: string)=>{constmodalSuffix=hasModalScrollContainer() ? timestampIdModalSuffix : '';//! this failed to detect overlayconsttimestampId=timestampIdPrefix+commentId+modalSuffix;returntimestampId;};constgetDateFromCommentId=(commentId: string): Date=>{consttimestampId=getTimestampIdFromCommentId(commentId);// this returns timestampId without 'inOverlay' suffix so element can't be foundconsttimestampElement=document.querySelector<HTMLElement>(`#${timestampId}`);if(!timestampElement)thrownewMyElementNotFoundDOMException(`Comment timestamp element with timestampId: ${timestampId} not found.`);consttimeAgo=timestampElement.textContentasstring;constdate=relativeTimeStringToDate(timeAgo);returndate;};// this function fails to detect overlay because onScroll fired before onUrlChange // and onScroll has 1 second debounce delay which isn't enough for DOM to loadexportconsthasModalScrollContainer=(): boolean=>{constmodalScrollContainer=document.querySelector<HTMLElement>(modalScrollContainerSelector);returnBoolean(modalScrollContainer);};
Main point:onScroll fires before onUrlChange and onScroll has scrollDebounceWait of 1 seconds which isn't enough for DOM to load compared to urlChangeDebounceWait which waits for 2 seconds. Because of that overlay isn't detected and it generates comment timestampId without inOverlay suffix. Then that element isn't found and it throws an exception.
This happens because Reddit has SPA where url change doesn't really load new DOM, it just handles url and rerenders part of the existing DOM and the existing onScroll and onUrlChange event handlers remain attached. In handleUrlChange() I remove onScroll event handler but that doesn't seem enough to prevent onScroll from firing before onUrlChange.
There should be some better synchronization mechanism for which I don't yet have solution, maybe some global lock variables but it doesn't sound right.
consthandleUrlChange=async(previousUrl: string,currentUrl: string)=>{// modal or documentconstscrollElement=getScrollElement();if(hasArrivedToRedditThread(previousUrl,currentUrl)){scrollElement.addEventListener('scroll',debouncedScrollHandler);// listen keys on documentdocument.addEventListener('keydown',handleCtrlSpaceKeyDown);// test onUrlChange and onScroll independentlyawaithandleUrlChangeDom();}if(hasLeftRedditThread(previousUrl,currentUrl)){scrollElement.removeEventListener('scroll',debouncedScrollHandler);}};
The text was updated successfully, but these errors were encountered:
I have documented it with comments in this commit:
390e8ac
This exception is handled but nevertheless it would be good to prevent it from happening at all. It happens sometimes when you navigate back from Reddit thread back to subreddit page.
It gets caught here in
handleScrollDom()
:export const handleScrollDom = async () => {
It originates from here:
const getDateFromCommentId = (commentId: string): Date => {
Main point:
onScroll
fires beforeonUrlChange
andonScroll
hasscrollDebounceWait
of 1 seconds which isn't enough for DOM to load compared tourlChangeDebounceWait
which waits for 2 seconds. Because of that overlay isn't detected and it generates commenttimestampId
withoutinOverlay
suffix. Then that element isn't found and it throws an exception.export const scrollDebounceWait = 1000;
This happens because Reddit has SPA where url change doesn't really load new DOM, it just handles url and rerenders part of the existing DOM and the existing
onScroll
andonUrlChange
event handlers remain attached. InhandleUrlChange()
I removeonScroll
event handler but that doesn't seem enough to preventonScroll
from firing beforeonUrlChange
.There should be some better synchronization mechanism for which I don't yet have solution, maybe some global lock variables but it doesn't sound right.
const handleUrlChange = async (previousUrl: string, currentUrl: string) => {
The text was updated successfully, but these errors were encountered: