fix(redirects): drop self-redirects at load time instead of serving a loop - #519
Draft
igoramf wants to merge 1 commit into
Draft
fix(redirects): drop self-redirects at load time instead of serving a loop#519igoramf wants to merge 1 commit into
igoramf wants to merge 1 commit into
Conversation
igoramf
force-pushed
the
fix/redirect-csv-query-self-loop
branch
from
September 1, 2026 10:55
06855ee to
6f611cc
Compare
This was referenced Sep 1, 2026
… loop
A rule whose source and target resolve to the same page answers every request
with a redirect back to the URL just asked for: ERR_TOO_MANY_REDIRECTS.
Bulk migration exports carry these rows, and `normalizePath` manufactures more:
it reduces an absolute `from` to `new URL(p).pathname`, which drops the query.
A row scoped to one legacy query
https://www.example.com/aliancas?map=category-1 -> /aliancas
therefore becomes `/aliancas -> /aliancas` and takes the page down. One
production storefront hit this twice from the same CSV — once on `/`, via a
`http://blog.example.com/,/` row, and once on a category page.
The Fresh loader this SDK replaced (deco-cx/apps
`website/loaders/redirectsFromCsv.ts`) had a `from === to` guard for exactly
this. Restore it, comparing after normalization so the collapsed rows above are
caught too.
Host is compared whenever both sides carry one, so a genuine cross-origin
redirect to the same path (`/x -> https://other.example.com/x`) still fires.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
igoramf
force-pushed
the
fix/redirect-csv-query-self-loop
branch
from
September 1, 2026 11:19
6f611cc to
e5b07c7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Primeiro de três PRs saídos do mesmo incidente. Este é o fix do bug; os outros dois estão listados no fim.
O bug
Uma regra cuja origem e destino resolvem para a mesma página responde toda request com um redirect para a URL que o browser acabou de pedir →
ERR_TOO_MANY_REDIRECTS.Exports de migração em massa trazem essas linhas prontas, e o
normalizePathfabrica mais: ele reduz umfromabsoluto anew URL(p).pathname, epathnamenão inclui a query. Então uma linha que só queria limpar uma URL legada de categoria:vira
exact["/aliancas"] = { to: "/aliancas" }e derruba a página inteira.Aconteceu duas vezes no mesmo storefront, a partir do mesmo CSV:
http://blog.montecarlo.com.br/,/,PERMANENThttps://www.montecarlo.com.br/aliancas?map=category-1,/aliancas,PERMANENT/aliancasNas duas vezes o contorno foi apagar a linha do CSV. Isso não escala: são ~3000 linhas de dump, e qualquer sync futuro reintroduz.
Por que o loader Fresh não tinha isso
deco-cx/apps@0.161.0/website/loaders/redirectsFromCsv.ts, que este SDK substituiu:O guard existia. O port perdeu. Este PR devolve, comparando depois da normalização — é justamente aí que as linhas acima colapsam.
Comportamento
/a → /ahttps://site/x?q=1 → /xhttp://blog.site/ → //a/ → /a,/A → /a/x → /x?ref=1/x → https://other.site/x/old → /new,/blog/* → /news/*O host é comparado sempre que os dois lados carregam um, então redirect cross-origin para o mesmo path continua disparando.
Testes
packages/blocks/src/sdk/redirects.test.ts, 9 casos montados sobre as linhas reais do CSV do incidente. 7 falham nomain:Com o patch: 9/9. Suíte do pacote: 756 passed (56 arquivos).
Trade-off que este PR assume
O guard descarta a regra em vez de consertá-la.
?map=category-1 → /aliancasé um redirect legítimo, que o Fresh honra hoje casando a href inteira (isHref: true), e aqui ele morre silenciosamente. É a escolha certa para um fix de loop — melhor perder um redirect do que derrubar uma página — mas é perda de comportamento.Restaurar isso é o assunto do PR seguinte, empilhado neste:
Redirect.search, matching por query nomatchRedirect). Devolve o comportamento que o Fresh tem hoje.PERMANENTmaiúsculo virando 302 (~3000 redirects rebaixados de 301).🤖 Generated with Claude Code