fix(odeme): iyziInit'i silmek yerine güvenli sıfırla
iyzico bundle'ı `iyziInit`i global `var` ile tanımlıyor; property non-configurable olduğu için `delete window.iyziInit` strict mode'da TypeError fırlatıyordu. Önce delete denenir, olmazsa undefined atanır — script'in aradığı `typeof ... == 'undefined'` koşulu iki yolla da sağlanır. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import { useEffect, useMemo } from "react";
|
||||
//
|
||||
// iyzico script'i `typeof iyziInit == 'undefined'` koruması taşır: aynı oturumda
|
||||
// ikinci kez mount olursa (geri gel / tekrar dene) global temizlenmezse form
|
||||
// çizilmez. Bu yüzden enjeksiyondan önce ve unmount'ta global silinir.
|
||||
// çizilmez. Bu yüzden enjeksiyondan önce ve unmount'ta global sıfırlanır.
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -17,6 +17,23 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
// iyzico bundle'ı `iyziInit`i global `var` ile tanımlıyor; bu da property'yi
|
||||
// non-configurable yapıyor, yani `delete window.iyziInit` strict mode'da
|
||||
// TypeError fırlatıyor ("Cannot delete property 'iyziInit'"). Önce silmeyi
|
||||
// dene, olmazsa undefined ata — script'in aradığı `typeof ... == 'undefined'`
|
||||
// koşulu iki yolla da sağlanır.
|
||||
function iyziInitSifirla() {
|
||||
try {
|
||||
delete window.iyziInit;
|
||||
} catch {
|
||||
try {
|
||||
window.iyziInit = undefined;
|
||||
} catch {
|
||||
// global kilitliyse yapacak bir şey yok; form yine de çizilmeye çalışılır
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function IyzicoFormu({ icerik }: { icerik: string }) {
|
||||
const govde = useMemo(
|
||||
() => icerik.match(/<script[^>]*>([\s\S]*?)<\/script>/i)?.[1],
|
||||
@@ -25,13 +42,13 @@ export function IyzicoFormu({ icerik }: { icerik: string }) {
|
||||
|
||||
useEffect(() => {
|
||||
if (!govde) return;
|
||||
delete window.iyziInit;
|
||||
iyziInitSifirla();
|
||||
const script = document.createElement("script");
|
||||
script.text = govde;
|
||||
document.body.appendChild(script);
|
||||
return () => {
|
||||
script.remove();
|
||||
delete window.iyziInit;
|
||||
iyziInitSifirla();
|
||||
};
|
||||
}, [govde]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user