Widget pages rewrite in-page anchor hashes now that the Observations Widget can go on any page

Aperta
#1,379 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
54/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
next.js, typescript
Ambito
frontend

Direzione di ricerca

Start with src/components/NACWidget/WidgetRouterHandler.client.tsx and inspect how its effect handles hashes that do not match widget routes. Then read the observations router catch-all in afp-public-widgets/src/apps/observations/router/index.js and reproduce the issue with an in-page anchor and starting filters. Done means ordinary anchor hashes remain intact and do not reset the widget filters, while widget-route hashes continue to work.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

needs-triage

Problem

WidgetRouterHandler replaces any URL hash it doesn't recognise as a widget route with the widget's starting path. That was harmless on the dedicated widget pages (/observations, /forecasts/avalanche, …), which have no in-page anchors. Since #1375 (Observations Widget block with starting filters, on pages and posts), editors can put the observations widget on any page, post, or home page, and there it breaks ordinary anchors:

  • Loading /about#donate on a page with the widget rewrites the URL to /about#/view/observations, so the anchor is lost from the address bar and from anything the visitor copies or bookmarks.
  • Clicking an in-page link to #section after the widget mounts triggers the widget's own hash router. Its catch-all route (/:pathMatch(.*)* in afp-public-widgets/src/apps/observations/router/index.js) redirects to /view/observations and drops the editor's starting filters, and WidgetRouterHandler also rewrites the hash.

The browser usually still scrolls to the anchor before the rewrite, so the visible damage is the URL and the widget resetting its filters.

Where

  • src/components/NACWidget/WidgetRouterHandler.client.tsx: the effect treats every hash that fails the widget page's path matchers as invalid.
  • The observations widget's catch-all route in afp-public-widgets.

Possible fix

Only treat hashes that look like widget routes (#/…) as the widget's. Leave any other hash alone in WidgetRouterHandler. The widget's catch-all redirect would still fire on hashchange, so a complete fix may also need a change in afp-public-widgets (e.g. ignore hashes that don't start with /).

Repro

  1. Add an Observations Widget block to a page that also has a rich-text link to #some-heading (or load the page with #some-heading in the URL).
  2. Load the page, or click the link.
  3. The hash becomes #/view/observations and the widget's starting filters are gone.
Lingua principale
TypeScript
Stelle
6
Fork
2
Merge medio
1g 11h
PR unite (30g)
35

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NWACus/web

Tutte le issue di NWACus/web

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.