Explorer HTML v0.9: Refactoring to async fetch - #2080
Conversation
Refactoring to avoid constant reloads of the HTML file: - Create showPage() function to query the node, update the URL parameters (without reload) and call the data display functions. - Replace 'xmlhttp' query logic with async 'fetch' - Replace links in menus and search with calls to showPage(). - Change UrlSelf() to use showPage(). - Change MakeLinkToOlderBlocks() and MakeLinkToNewerBlocks() to use UrlSelf(). - Change UrlBlock() to use the 'adj' parameter (for PoS chains). - Rename columnHeaders* variables to allow switching between PoW and PoS vocabulary. - Remove initialization logic of global parameters as they will now be set (and updated) from within showPage(). - Add pageConfig and paramConfig global variables to define the characteristics of all pages and all query parameters (including their type). - Rename urlPrefix as g_urlPrefix.
|
Reviewed the refactor — the direction is good: ✅ 1.
|
- Add style for class 'p.errorMessage'. - Encode '&' in javascript links, for security. - Copy object content instead of creating an alias for 'columnHeaders'. - Add a showPage counter to avoid mixing fetched data when switching pages too fast. - Default unknown 'type=' in URL to 'status' - Tests done: 'replaceState' and 'pushState' work well when loading the app locally through 'file://"
- Ensure the div containers still exist before displaying Atomic or Asset Swap totals. - In showPage(), call the display function *after* the fetch try, so that any display error remains distinguishable from network errors.
|
Went through the six new commits ( Also worth saying: the Three things left — all three since fixed in ✅ 1. The generation guard covers only the success path} catch (err) {
console.error('Failed to load page ' + page_id + ':', err);
document.getElementById('MainContent').innerHTML = `…`; // line 3577
return;
}
// If another page has already been called during fetch, interrupt this old one
if (showPageCounter !== g_showPageCounter) { return; } // line 3587The check at 3587 is after the Reproduced by stalling The status page renders correctly, then the dead hdrs request overwrites it with an error screen whose Retry link points at } catch (err) {
if (showPageCounter !== g_showPageCounter) { return; }
console.error(…);
…
}Fixed in ✅ 2. Narrowing the
|
- Correct some typos. - Avoid fetch error being displayed if the users has already moved to another page. - Add a try/catch for possible errors in data parsing & display.
Refactoring to a "single page app" using async fetch to avoid HTML reloads.
See details of changes in commits.
A PR is made for it alone because it significantly changes the code in many places.