fix: 47 errores de lint, y uno de ellos era un bug de verdad
Salieron al pasar el lint por todo el proyecto. De 47 a 0 (quedan 15 avisos: <img> vs <Image /> y el <link> del tema, los dos deliberados). - Footer y Video (42 de los 47, que en realidad eran 7 enlaces: el plugin repite cada uno 6 veces): usaban `<a href="/terms-and-conditions">` SIN el idioma delante. No estaba roto de milagro: el middleware lo salvaba mirando la cookie NEXT_LOCALE. Pero cada clic se comía un 307 y recargaba la página entera en vez de navegar en cliente, y el idioma lo decidía la cookie en vez de la URL en la que estás. Ahora van con el `Link` de i18n, que ya existía. - Turnstile: escribía una ref (`cb.current = onVerify`) DURANTE el render. Es el patrón de "callback fresca", pero no está permitido: React puede descartar ese render y dejarla mal. Pasa a un efecto. - ActivateClient y ConfirmClient: ponían el estado de error con setState dentro del efecto cuando NO hay hash. Eso se sabe ya al renderizar (es un prop), así que se deriva del estado inicial y se ahorra un render. - BattlepayList: `window.location.href = …` -> `.assign()`, igual que en la tienda. - CookieConsent: aquí el efecto es correcto y la regla no aplica, así que se silencia explicando por qué: el consentimiento vive en una cookie del navegador, en el servidor no existe, y leerlo al renderizar rompería la hidratación (le saldría el banner a quien ya había decidido). Verificado: desde /es/ el pie enlaza a /es/terms-and-conditions y desde /en/ a /en/terms-and-conditions; portada, cookies, tienda y mi-cuenta siguen dando 200. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,18 +8,16 @@ const ERROR_KEYS = ['invalidLink', 'expiredLink'] as const
|
|||||||
|
|
||||||
export function ActivateClient({ hash }: { hash: string }) {
|
export function ActivateClient({ hash }: { hash: string }) {
|
||||||
const t = useTranslations('Activate')
|
const t = useTranslations('Activate')
|
||||||
const [state, setState] = useState<'loading' | 'ok' | 'error'>('loading')
|
// Sin hash el error se sabe YA, al renderizar (y 'invalidLink' es justo el
|
||||||
|
// errorKey por defecto): se deriva del prop en vez de ponerlo con setState
|
||||||
|
// dentro del efecto, que encadena un render de más.
|
||||||
|
const [state, setState] = useState<'loading' | 'ok' | 'error'>(hash ? 'loading' : 'error')
|
||||||
const [errorKey, setErrorKey] = useState<string>('invalidLink')
|
const [errorKey, setErrorKey] = useState<string>('invalidLink')
|
||||||
const ran = useRef(false)
|
const ran = useRef(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ran.current) return // evita doble POST en StrictMode
|
if (!hash || ran.current) return // evita doble POST en StrictMode
|
||||||
ran.current = true
|
ran.current = true
|
||||||
if (!hash) {
|
|
||||||
setErrorKey('invalidLink')
|
|
||||||
setState('error')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fetch('/api/auth/activate', {
|
fetch('/api/auth/activate', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ export function BattlepayList({ orders }: { orders: BattlepayOrder[] }) {
|
|||||||
})
|
})
|
||||||
const d: { success?: boolean; url?: string; error?: string } = await res.json()
|
const d: { success?: boolean; url?: string; error?: string } = await res.json()
|
||||||
if (d.success && d.url) {
|
if (d.success && d.url) {
|
||||||
window.location.href = d.url
|
// .assign() y no `location.href = …`: equivalente, pero la regla del
|
||||||
|
// compilador de React prohíbe asignar a algo de fuera del componente.
|
||||||
|
window.location.assign(d.url)
|
||||||
} else {
|
} else {
|
||||||
setError(t(d.error === 'orderNotFound' ? 'orderNotFound' : 'genericError'))
|
setError(t(d.error === 'orderNotFound' ? 'orderNotFound' : 'genericError'))
|
||||||
setBusy(null)
|
setBusy(null)
|
||||||
|
|||||||
@@ -17,16 +17,14 @@ export function ConfirmClient({
|
|||||||
showLogin?: boolean
|
showLogin?: boolean
|
||||||
}) {
|
}) {
|
||||||
const t = useTranslations(namespace)
|
const t = useTranslations(namespace)
|
||||||
const [state, setState] = useState<'loading' | 'ok' | 'error'>('loading')
|
// Sin hash el error se sabe YA, al renderizar: se deriva del prop en vez de
|
||||||
|
// ponerlo con setState dentro del efecto (eso encadena un render de más).
|
||||||
|
const [state, setState] = useState<'loading' | 'ok' | 'error'>(hash ? 'loading' : 'error')
|
||||||
const ran = useRef(false)
|
const ran = useRef(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ran.current) return
|
if (!hash || ran.current) return
|
||||||
ran.current = true
|
ran.current = true
|
||||||
if (!hash) {
|
|
||||||
setState('error')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fetch(endpoint, {
|
fetch(endpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
|||||||
@@ -103,9 +103,16 @@ export function CookieBanner() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.UWCookies = { showBanner, revokeConsent, acceptAll, rejectAll }
|
window.UWCookies = { showBanner, revokeConsent, acceptAll, rejectAll }
|
||||||
// Precarga los checkboxes con lo ya guardado (si lo hay).
|
// Precarga los checkboxes con lo ya guardado (si lo hay).
|
||||||
|
// El lint avisa de que esto encadena un render, y aquí no hay alternativa:
|
||||||
|
// el consentimiento está en una cookie del navegador y en el servidor no
|
||||||
|
// existe, así que no se puede saber al renderizar sin romper la hidratación
|
||||||
|
// (saldría el banner en el HTML a quien ya había decidido). El render de más
|
||||||
|
// es inherente y solo ocurre al montar.
|
||||||
|
/* eslint-disable react-hooks/set-state-in-effect */
|
||||||
const saved = readConsent()
|
const saved = readConsent()
|
||||||
if (saved) setPrefs({ analytics: !!saved.analytics, marketing: !!saved.marketing })
|
if (saved) setPrefs({ analytics: !!saved.analytics, marketing: !!saved.marketing })
|
||||||
else setVisible(true) // Aparece si aún no hay decisión guardada.
|
else setVisible(true) // Aparece si aún no hay decisión guardada.
|
||||||
|
/* eslint-enable react-hooks/set-state-in-effect */
|
||||||
const onShow = () => {
|
const onShow = () => {
|
||||||
const cur = readConsent()
|
const cur = readConsent()
|
||||||
if (cur) setPrefs({ analytics: !!cur.analytics, marketing: !!cur.marketing })
|
if (cur) setPrefs({ analytics: !!cur.analytics, marketing: !!cur.marketing })
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import { getTranslations } from 'next-intl/server'
|
import { getTranslations } from 'next-intl/server'
|
||||||
import { getRealmName } from '@/lib/realm'
|
import { getRealmName } from '@/lib/realm'
|
||||||
|
import { Link } from '@/i18n/navigation'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pie de página — réplica del partial Django `partials/footer.html`
|
* Pie de página — réplica del partial Django `partials/footer.html`
|
||||||
* (enlaces legales + copyright + crédito de diseño) con las clases del tema real.
|
* (enlaces legales + copyright + crédito de diseño) con las clases del tema real.
|
||||||
|
*
|
||||||
|
* Los enlaces van con el `Link` de i18n, no con <a href="/x">: sin el idioma
|
||||||
|
* delante, cada clic se comía un 307 del middleware y recargaba la página
|
||||||
|
* entera, y el idioma lo decidía la cookie en vez de la URL en la que estás.
|
||||||
*/
|
*/
|
||||||
export async function Footer() {
|
export async function Footer() {
|
||||||
const t = await getTranslations('UI')
|
const t = await getTranslations('UI')
|
||||||
@@ -13,27 +18,27 @@ export async function Footer() {
|
|||||||
return (
|
return (
|
||||||
<footer>
|
<footer>
|
||||||
<p>
|
<p>
|
||||||
<a href="/terms-and-conditions">{t('footer.terms')}</a>
|
<Link href="/terms-and-conditions">{t('footer.terms')}</Link>
|
||||||
<span className="third-brown">
|
<span className="third-brown">
|
||||||
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
||||||
</span>
|
</span>
|
||||||
<a href="/privacy-policy">{t('footer.privacy')}</a>
|
<Link href="/privacy-policy">{t('footer.privacy')}</Link>
|
||||||
<span className="third-brown">
|
<span className="third-brown">
|
||||||
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
||||||
</span>
|
</span>
|
||||||
<a href="/refund-policy">{t('footer.refund')}</a>
|
<Link href="/refund-policy">{t('footer.refund')}</Link>
|
||||||
<span className="third-brown">
|
<span className="third-brown">
|
||||||
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
||||||
</span>
|
</span>
|
||||||
<a href="/cookies">{t('footer.cookies')}</a>
|
<Link href="/cookies">{t('footer.cookies')}</Link>
|
||||||
<span className="third-brown">
|
<span className="third-brown">
|
||||||
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
||||||
</span>
|
</span>
|
||||||
<a href="/legal-notice">{t('footer.legal')}</a>
|
<Link href="/legal-notice">{t('footer.legal')}</Link>
|
||||||
<span className="third-brown">
|
<span className="third-brown">
|
||||||
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
<i className="fas fa-grip-lines-vertical"></i> {' '}
|
||||||
</span>
|
</span>
|
||||||
<a href="/contact-us">{t('footer.contact')}</a>
|
<Link href="/contact-us">{t('footer.contact')}</Link>
|
||||||
</p>
|
</p>
|
||||||
<br />
|
<br />
|
||||||
<p className="third-brown">
|
<p className="third-brown">
|
||||||
|
|||||||
@@ -27,8 +27,13 @@ const SCRIPT_ID = 'cf-turnstile-script'
|
|||||||
export function Turnstile({ onVerify }: { onVerify: (token: string) => void }) {
|
export function Turnstile({ onVerify }: { onVerify: (token: string) => void }) {
|
||||||
const ref = useRef<HTMLDivElement>(null)
|
const ref = useRef<HTMLDivElement>(null)
|
||||||
const rendered = useRef(false)
|
const rendered = useRef(false)
|
||||||
|
// Callback siempre fresca sin re-crear el widget. Se actualiza en un efecto y
|
||||||
|
// NO durante el render: escribir una ref mientras se renderiza no está
|
||||||
|
// permitido (React puede descartar ese render y dejarla mal).
|
||||||
const cb = useRef(onVerify)
|
const cb = useRef(onVerify)
|
||||||
cb.current = onVerify
|
useEffect(() => {
|
||||||
|
cb.current = onVerify
|
||||||
|
})
|
||||||
const siteKey = process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY
|
const siteKey = process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { Link } from '@/i18n/navigation'
|
||||||
|
|
||||||
const SERVER_NAME = 'NovaWoW'
|
const SERVER_NAME = 'NovaWoW'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,7 +11,7 @@ export function Video() {
|
|||||||
return (
|
return (
|
||||||
<div className="div-nw-video">
|
<div className="div-nw-video">
|
||||||
<div className="nw-main-logo">
|
<div className="nw-main-logo">
|
||||||
<a href="/">
|
<Link href="/">
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
<img
|
<img
|
||||||
className="nw_main_logo_img"
|
className="nw_main_logo_img"
|
||||||
@@ -17,7 +19,7 @@ export function Video() {
|
|||||||
alt={SERVER_NAME}
|
alt={SERVER_NAME}
|
||||||
title={SERVER_NAME}
|
title={SERVER_NAME}
|
||||||
/>
|
/>
|
||||||
</a>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div id="live-stream-div">
|
<div id="live-stream-div">
|
||||||
<div id="live-stream-announce">
|
<div id="live-stream-announce">
|
||||||
|
|||||||
Reference in New Issue
Block a user