hodfa840 commited on
Commit
eccb3a4
Β·
1 Parent(s): f4d8632

Fix runtime error + projects redirect

Browse files

- Remove injectFlagImages: it mutated React-managed DOM nodes causing
LS to crash with 'Cannot read properties of null (reading innerHTML)'
because React lost track of replaced text nodes
- Fix interceptProjectsNav: call checkPath() immediately on script load
so direct navigation to /projects?page=N also redirects to our custom
landing page (previously only SPA pushState was intercepted, not hard
navigations); /projects/ without page= param is left alone (our page)

Files changed (1) hide show
  1. ls_proxy_hf.py +11 -1
ls_proxy_hf.py CHANGED
@@ -281,11 +281,21 @@ PRIVACY_SCRIPT = """
281
  })();
282
 
283
  // ── React Router intercept β†’ hard reload for custom /projects/ page ───────
 
 
284
  (function interceptProjectsNav() {
285
  function checkPath() {
286
  var p = window.location.pathname;
287
- if (p === '/projects' || p === '/projects/') window.location.replace('/projects/');
 
 
 
 
 
 
288
  }
 
 
289
  var origPush = history.pushState, origReplace = history.replaceState;
290
  history.pushState = function() { origPush.apply(this, arguments); checkPath(); };
291
  history.replaceState = function() { origReplace.apply(this, arguments); checkPath(); };
 
281
  })();
282
 
283
  // ── React Router intercept β†’ hard reload for custom /projects/ page ───────
284
+ // Also fires on load to catch direct navigation to /projects?page=N.
285
+ // Does NOT redirect /projects/ without page= param (that's our own custom page).
286
  (function interceptProjectsNav() {
287
  function checkPath() {
288
  var p = window.location.pathname;
289
+ var q = window.location.search;
290
+ // /projects (no slash) = SPA internal route β€” always redirect
291
+ // /projects/?page=N = SPA pagination β€” redirect
292
+ // /projects/ = our custom landing page β€” leave alone
293
+ if (p === '/projects' || (p === '/projects/' && q.indexOf('page=') !== -1)) {
294
+ window.location.replace('/projects/');
295
+ }
296
  }
297
+ // Run immediately (catches direct URL navigation and pagination links)
298
+ checkPath();
299
  var origPush = history.pushState, origReplace = history.replaceState;
300
  history.pushState = function() { origPush.apply(this, arguments); checkPath(); };
301
  history.replaceState = function() { origReplace.apply(this, arguments); checkPath(); };