feat: CSR에서 __customAction 설정 및 업데이트 로직 추가
This commit is contained in:
@@ -15,6 +15,15 @@
|
||||
const runtimeConfig = useRuntimeConfig()
|
||||
const staticUrl = runtimeConfig.public.staticUrl
|
||||
|
||||
// CSR에서만 __customAction 즉시 설정 (HTML 렌더링 전에 필요)
|
||||
// handleCustomAction이 정의되기 전이므로 나중에 업데이트됨
|
||||
if (import.meta.client) {
|
||||
;(window as any).__customAction = () => {
|
||||
// handleCustomAction이 아직 정의되지 않았을 수 있으므로 무시
|
||||
// onMounted에서 실제 함수로 교체됨
|
||||
}
|
||||
}
|
||||
|
||||
const coerceToString = (value: unknown): string => {
|
||||
if (typeof value === 'string') return value
|
||||
if (typeof value === 'number') return String(value)
|
||||
@@ -474,6 +483,11 @@
|
||||
if (!import.meta.client) return
|
||||
if (!html) return
|
||||
|
||||
// HTML이 업데이트될 때마다 __customAction 재설정 (CSR에서만)
|
||||
if (import.meta.client) {
|
||||
;(window as any).__customAction = handleCustomAction
|
||||
}
|
||||
|
||||
scriptsLoaded.value = false
|
||||
|
||||
let cancelled = false
|
||||
@@ -498,19 +512,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (!cancelled) scriptsLoaded.value = true
|
||||
// 스크립트 로드 후에도 __customAction 재설정 (CSR에서만)
|
||||
if (!cancelled && import.meta.client) {
|
||||
scriptsLoaded.value = true
|
||||
;(window as any).__customAction = handleCustomAction
|
||||
} else if (!cancelled) {
|
||||
scriptsLoaded.value = true
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// onMounted에서 초기화 코드 실행
|
||||
// onMounted에서 초기화 코드 실행 (CSR에서만)
|
||||
onMounted(() => {
|
||||
if (!import.meta.client) return
|
||||
|
||||
const container = customContainerRef.value
|
||||
if (!container) return
|
||||
|
||||
// onclick="window.__customAction(this)" 지원
|
||||
// onclick="window.__customAction(this)" 지원 (CSR에서만)
|
||||
;(window as any).__customAction = handleCustomAction
|
||||
|
||||
// onclick을 못 쓰는 케이스 대비: 이벤트 위임도 같이 지원
|
||||
|
||||
Reference in New Issue
Block a user