Plugin de retry
Plugin de retry
O Plugin de retry fornece uma robust mecanismo de retry for Module Federation. Quando módulos remotos ou recursos fail para carregar, it retries automatically para keep your app stable.
Features
- Automatic retries: Improve stability by retrying falhou recurso carrega
- Domain rotation: Switch across multiple backup domains automatically
- Cache-busting: Add query parameters para avoid cache interference on retries
- Flexible configuração: Customize retry times, delay, e callbacks
Instale
Migration Guia
De v0.18.x para v0.19.x
O plugin configuração has been simplified. O old fetch e script configuração objetos são deprecated:
Uso
Method1: Usado no plugin de build
Method2: Usado no runtime puro
Configuração
Básico
retryTimes
- Tipo:
number - Opcional
- Number de retries, padrão é 3
retryDelay
- Tipo:
number - Opcional
- Delay entre retries em milliseconds, padrão é 1000
Avançado
domains
- Tipo:
string[] - Opcional
- Backup domains for rotation. Padrão é um empty array
addQuery
- Tipo:
boolean | ((context: { times: number; originalQuery: string }) => string) - Opcional
- Whether para append uma query parameter quando retrying, padrão é false
- Se uma função é fornecido, it receives retry count e o original query string, e deve retornar o novo query string
fetchOptions
- Tipo:
RequestInit - Opcional
- Custom buscar opções, padrão é um empty objeto
manifestDomains
- Tipo:
string[] - Opcional
- Domain rotation list usado quando fetching o manifest (e.g.
mf-manifest.json). Takes precedence overdomainsfor manifest buscar retries. Other recursos still usedomains.
Callbacks
onRetry
- Tipo:
({ times, domains, url, tagName }: { times?: number; domains?: string[]; url?: string; tagName?: string }) => void - Opcional
- Triggered on each retry
- Params:
timescurrent retry number,domainsdomain list,urlrequest URL,tagNamerecurso tipo
onSuccess
- Tipo:
({ domains, url, tagName }: { domains?: string[]; url?: string; tagName?: string; }) => void - Opcional
- Triggered quando uma retry finally succeeds
- Params:
domainsdomain list,urlrequest URL,tagNamerecurso tipo
onError
- Tipo:
({ domains, url, tagName }: { domains?: string[]; url?: string; tagName?: string; }) => void - Opcional
- Triggered quando all retries fail
- Params:
domainsdomain list,urlrequest URL,tagNamerecurso tipo
Details
Retry logic
O plugin retries automatically quando uma recurso fails para carregar. O number de retries é controlled by retryTimes. Por exemplo:
retryTimes: 3means up para 3 retries (depois o primeiro attempt)- Uma delay de
retryDelayms é applied antes each retry
Domain rotation
Quando domains é configured, o plugin rotates o host on each retry:
Order de attempts:
- Initial attempt: original URL
- 1st retry: switch para
cdn2.example.com - 2nd retry: switch para
cdn3.example.com - 3rd retry: switch para
cdn1.example.com
Cache-busting
Use addQuery para adicionar query parameters during retries para avoid cache interference:
Você pode também forneça uma função:
Callbacks
Você pode monitor o retry lifecycle com callbacks:
Callback params:
times: current retry count (começa de 1)domains: o current domain listurl: current request URLtagName: recurso tipo ('buscar' ou 'script')
Use cases
1. CDN failover
2. Unstable networks
3. Monitoring e logging
Notes
- Performance: High retry counts increase carregamento time; tune for your environment
- Domains: Ensure all domains em
domainsserve o mesmo recurso - Caching: Se
addQueryé habilitado, consider CDN caching estratégia - Erro handling: Depois all retries fail, o original erro é thrown; handle it upstream
Erro codes
RUNTIME_008: Resource carregue falha esse triggers o mecanismo de retry