Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Remove repository tab polling and rename Code to Source

cc7faea36a31373079df8fce68c1bc20a44873a0 · Keenan Nemetz · 3d ago · parent 0a12642f

Remove repository tab polling and rename Code to Source

The tab row no longer polls its open counts, so the /{name}/counts endpoint, its htmx trigger, and the badge animation are gone. The unfocused-window note has been removed while the other live regions still pause.

The Code tab is now Source, served at /{name}/source; links, sitemap entries, markdown tree links, and tests follow the new route.

server/web/static/app.js +5−60

@@ -863,44 +863,25 @@ const since = (unix, now) => {
863 863 })();
864 864
865 865 // Live regions. A page in an unfocused window is not being watched, so its polls
866 // stop asking the server for an answer nobody reads. The last answer stays on
867 // screen with how old it is, because a duration that keeps counting beside a
868 // status that stopped moving is a lie. Returning to the window refreshes at once
869 // instead of waiting out the interval: htmx polls listen for vole-refresh, and
870 // the run page's own loop resumes on the same event. Only queued and running
871 // rows are marked; a finished run cannot change its word.
866 // stop asking the server for an answer nobody reads. Returning to the window
867 // refreshes at once instead of waiting out the interval: htmx polls listen for
868 // vole-refresh, and the run page's own loop resumes on the same event. Only
869 // queued and running rows are marked; a finished run cannot change its word.
872 870 //
873 871 // HTMX compiles an hx-trigger filter with Function(), which the CSP forbids
874 872 // (script-src 'self'), so the skip is here, on htmx:beforeRequest, and not in the
875 873 // trigger. An hx-trigger that grows a filter is the CSP error again.
876 874 (() => {
877 const note = document.querySelector('[data-live-note]');
878 875 const regions = new Set();
879 // The markup was rendered just now, so the page's own time is the age of
880 // everything on it until a poll replaces part of it.
881 const pageTime = Date.now();
882 876
883 877 const regionOf = (element) => (element && element.closest ? element.closest('[data-live]') : null);
884 878
885 879 const sync = () => {
886 if (!note) return;
887 if (!regions.size) {
888 note.hidden = true;
889 document.body.classList.remove('is-stale');
890 return;
891 }
892 let oldest = Infinity;
893 regions.forEach((region) => {
894 oldest = Math.min(oldest, Number(region.dataset.refreshedAt) || pageTime);
895 });
896 document.body.classList.add('is-stale');
897 note.hidden = false;
898 note.textContent = `updates paused · last checked ${since(oldest / 1000, Date.now())}`;
880 document.body.classList.toggle('is-stale', regions.size > 0);
899 881 };
900 882
901 883 const mark = (region) => {
902 884 if (!region || region.classList.contains('is-stale')) return;
903 if (!region.dataset.refreshedAt) region.dataset.refreshedAt = String(pageTime);
904 885 region.classList.add('is-stale');
905 886 regions.add(region);
906 887 sync();
@@ -908,16 +889,12 @@ const since = (unix, now) => {
908 889
909 890 const fresh = (region) => {
910 891 if (!region) return;
911 region.dataset.refreshedAt = String(Date.now());
912 892 if (!region.classList.contains('is-stale')) return;
913 893 region.classList.remove('is-stale');
914 894 regions.delete(region);
915 895 sync();
916 896 };
917 897
918 document.querySelectorAll('[data-live]').forEach((region) => {
919 region.dataset.refreshedAt = String(pageTime);
920 });
921 898 document.addEventListener('vole-stale', (event) => mark(regionOf(event.target)));
922 899 document.addEventListener('vole-fresh', (event) => fresh(regionOf(event.target)));
923 900
@@ -942,40 +919,8 @@ const since = (unix, now) => {
942 919 document.addEventListener('visibilitychange', () => {
943 920 if (document.visibilityState === 'visible') refresh();
944 921 });
945
946 setInterval(() => {
947 if (document.visibilityState === 'visible' && regions.size) sync();
948 }, 1000);
949 922 })();
950 923
951 // The repository tabs poll their open counts, and a number changing while the
952 // reader is looking somewhere else is easy to miss. A badge that moved keeps one
953 // short ring; the page's first counts are the baseline, so only a later poll that
954 // changes a number marks the tab. An out-of-band response replaces one badge at a
955 // time, so every swap reads all of them: the badge that has not been replaced yet
956 // is still the value already recorded and is left alone.
957 (() => {
958 const seen = new Map();
959 const read = () => {
960 document.querySelectorAll('.tabs .chip-count[id]').forEach((badge) => {
961 const value = badge.textContent.trim();
962 if (seen.get(badge.id) === value) return;
963 const first = !seen.has(badge.id);
964 seen.set(badge.id, value);
965 if (first) return;
966 // The class is removed and the layout read in between so a second change
967 // restarts the animation instead of finding the class already applied.
968 badge.classList.remove('count-changed');
969 void badge.offsetWidth;
970 badge.classList.add('count-changed');
971 badge.addEventListener('animationend', () => badge.classList.remove('count-changed'), { once: true });
972 });
973 };
974 read();
975 document.body.addEventListener('htmx:oobAfterSwap', read);
976 })();
977
978
979 924 // 3D previews. three.js and its loaders are a large module, so the viewer is
980 925 // imported only when the page contains a model; the server renders a download
981 926 // link inside every [data-model] host, which is what stays if this never loads.