Safariμ—μ„œ 비동기 처리 ν›„ ν˜ΈμΆœν•˜λŠ” window.open() μš°νšŒν•΄μ„œ ν•΄κ²°

2025. 2. 5. 18:52Β·issue

 

κΈ°λŠ₯ μš”κ΅¬μ‚¬ν•­μ€ 'μ‹ κ³ ν•˜κΈ° λ²„νŠΌ ν΄λ¦­μ‹œ μ‹ κ³ ν•˜λŠ” 폼으둜 μ΄λ™ν•˜κΈ°' μ˜€λŠ”λ°, 이 μ΅œμ†Œ κΈ°λŠ₯λ§Œμ„ κ΅¬ν˜„ν•˜κ³  ν…ŒμŠ€νŠΈν•΄λ³΄λ‹ˆ μ‚¬μš©μž μž…μž₯μ—μ„œ μ‹ κ³ ν•˜λŠ” 폼에 ν•„μš”ν•œ 양식듀을 μž‘μ„±ν•˜κΈ° μœ„ν•΄μ„œλŠ” κΈ°μ‘΄ νŽ˜μ΄μ§€κ°€ λ³€κ²½λ˜μ§€ μ•ŠλŠ” 것이 μ‚¬μš©μž κ²½ν—˜μ— 더 쒋을 것 κ°™μ•˜μŠ΅λ‹ˆλ‹€.

 

κ·Έλž˜μ„œ νŒ€μ›λ“€κ³Ό λ…Όμ˜ ν›„ μ‹ κ³ ν•˜λŠ” 폼은 μƒˆ νƒ­μœΌλ‘œ μ—΄λ¦¬κ²Œ ν•˜κ³ , κΈ°μ‘΄ νŽ˜μ΄μ§€λŠ” 이동없이 μœ μ§€ν•˜λ„λ‘ν•˜λ©΄μ„œ, κΈ°μ‘΄ 기획/λ””μžμΈμ—μ„œ μžˆμ—ˆλ˜ ν† μŠ€νŠΈλŠ” μ‚­μ œν•˜λŠ” λ°©ν–₯으둜 μˆ˜μ •ν–ˆμŠ΅λ‹ˆλ‹€.

 

μƒˆ νƒ­μœΌλ‘œ μ—΄λ¦¬κ²Œ ν•˜λŠ” 것은 λ‹€μŒ μ½”λ“œμ™€ 같이 μžλ°”μŠ€ν¬λ¦½νŠΈ window 객체의 open ν•¨μˆ˜λ‘œ κ°„λ‹¨ν•˜κ²Œ κ΅¬ν˜„ν•  수 μžˆμ—ˆμŠ΅λ‹ˆλ‹€.

'use client'

export default function Page({
  params: { userId, messageId },
}: {
  params: { userId: string; messageId: string }
}) {
  const router = useRouter()
  const { mutateAsync } = usePatchMessageStatus()
  const changeStatus = async () => {
    const redirectURL = 'μͺ½μ§€ν•¨ 리슀트 url'
    const openReportForm = 'μ‹ κ³ ν•˜λŠ” ꡬ글폼 μ£Όμ†Œ'
     try {
        const response = await mutateAsync({
        messageId,
        status: 'reported',
      })
      window.open(openReportForm) // μƒˆλ‘œμš΄ 창으둜 μ‹ κ³  폼 μ—΄κΈ°
      router.push(redirectURL) // μͺ½μ§€ν•¨ 리슀트둜 이동
      if (!response) {
        console.error('Reported response is empty: ', response)
           router.back()
      }
    } catch (error) {
      console.error('Failed to change status from normal to reported: ', error)
          router.back()
    }
  }
  return (
  .....
  )}

 

 

ν¬λ‘¬μ—μ„œ 잘 μ—΄λ¦¬λŠ” κ±Έ ν™•μΈν–ˆλŠ”λ° 이후 μ‚¬νŒŒλ¦¬λ‘œ ν…ŒμŠ€νŠΈ ν•΄λ³΄λ‹ˆ μƒˆ 탭이 열리지 μ•Šμ•˜μŠ΅λ‹ˆλ‹€. νŒμ—… μ•Œλ¦Όμ‘°μ°¨λ„ λœ¨μ§€ μ•ŠμŒ.

 

MDN λ¬Έμ„œλ₯Ό μ°Ύμ•„λ³΄λ‹ˆ μ‚¬νŒŒλ¦¬μ—μ„œλŠ” click μ΄λ²€νŠΈκ°€ λ°œμƒν•œμ§€ 1000ms이후에 window.open λ©”μ„œλ“œκ°€ 호좜되면 νŒμ—…μ΄ μ°¨λ‹¨λœλ‹€κ³  ν•©λ‹ˆλ‹€.

 

μ–΄λ–€ 비동기 μž‘μ—… 후에 window.open()을 ν˜ΈμΆœν•˜λ €κ³  ν•˜λ©΄ κ·Έ μ‚¬μ΄μ˜ μ§€μ—° λ•Œλ¬Έμ— λΈŒλΌμš°μ €κ°€ 이λ₯Ό μ‚¬μš©μžκ°€ 직접 ν΄λ¦­ν•œ 것이 μ•„λ‹Œ μŠ€ν¬λ¦½νŠΈμ— μ˜ν•΄ μžλ™μœΌλ‘œ μƒμ„±λœ νŒμ—…μœΌλ‘œ μΈμ‹ν•˜κ³  차단할 수 μžˆλ‹€λŠ” λ‚΄μš©...

 

 

 

μ‚¬νŒŒλ¦¬μ—μ„œ 비동기 처리 후에 window.open()을 ν˜ΈμΆœν•˜λ„λ‘ μƒˆ 탭을 λ§Œλ“€κΈ° μœ„ν•΄μ„œ λ‹€μŒ μˆœμ„œλ₯Ό λ”°λ₯΄λŠ” 과정이 ν•„μš”ν–ˆμŠ΅λ‹ˆλ‹€

 

- 빈 νŒμ—…μ„ λ„μš°κ³ 

- ν•„μš”ν•œ 비동기λ₯Ό μˆ˜ν–‰ν•˜κ³ 

- 빈 νŒμ—…μ˜ location.hrefλ₯Ό λ°”κΎΌλ‹€.

 

κ·Έλž˜μ„œ κΈ°μ‘΄μ—” 띨둱 window.open(url) ν•˜λ˜ κ²ƒμ—μ„œ λ‹€μŒκ³Ό 같이 ν•¨μˆ˜λ₯Ό λ§Œλ“œλŠ” λ°©ν–₯으둜 μˆ˜μ •ν–ˆμŠ΅λ‹ˆλ‹€.

 

https://youtu.be/Waxwfmhaqxc

// src/shared/hooks/util/openTabUtil.ts
export const openInNewTab = (url: string) => {
  const newWindow = window.open(url, '_blank', 'noopener, popup')
  if (newWindow) newWindow.opener = null
}


// src/app/messagebox/[userId]/[type]/[messageId]/report/page.tsx
import { openInNewTab } from '@/shared/hooks/util/openTabUtil'

export default function Page({
  params: { userId, messageId },
}: {
  params: { userId: string; messageId: string }
}) {
  {/* μƒλž΅ */}
  const changeStatus = async () => {
    try {
      const response = await mutateAsync({
        messageId,
        status: 'reported',
      })
      openInNewTab(`μ‹ κ³ ν•˜λŠ” 폼 μ£Όμ†Œ`)
      if (!response) {
        router.back()
      }
    } catch (error) {
      router.back()
    }
  }
  
  return (
  {/* μƒλž΅ */}
  )
}

 

'issue' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

μ˜λ„μΉ˜ μ•Šκ²Œ λ³€κ²½λœ CRLF <=> LF ν•΄κ²°ν•˜κΈ°  (0) 2025.01.05
homebrew-core is a shallow clone. (brew)  (0) 2024.10.29
λΉŒλ“œ 쀑 svg Module not found error (Next.js)  (0) 2024.10.22
νšŒμ›κ°€μž…μ‹œ 이메일 인증 λ³΄μ•ˆ 이슈 (api endpoint κ΄€λ ¨)  (2) 2024.10.16
Git Error: RPC failed; HTTP 400 curl 22 The requested URL returned error: 400  (1) 2024.10.02
'issue' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€
  • μ˜λ„μΉ˜ μ•Šκ²Œ λ³€κ²½λœ CRLF <=> LF ν•΄κ²°ν•˜κΈ°
  • homebrew-core is a shallow clone. (brew)
  • λΉŒλ“œ 쀑 svg Module not found error (Next.js)
  • νšŒμ›κ°€μž…μ‹œ 이메일 인증 λ³΄μ•ˆ 이슈 (api endpoint κ΄€λ ¨)
nuew
nuew
🀸 재주 λ„˜λŠ” 쀑
  • nuew
    bloggg. . .πŸ¦–πŸ’₯
    nuew
  • 전체
    였늘
    μ–΄μ œ
    • λΆ„λ₯˜ 전체보기 (88)
      • issue (10)
      • baekjoon (41)
      • lecture recap (11)
      • What I Learn (26)
      • retrospective (0)
      • maeil-mail (0)
  • λΈ”λ‘œκ·Έ 메뉴

    • ν™ˆ
    • νƒœκ·Έ
    • λ°©λͺ…둝
  • 링크

  • 곡지사항

  • 인기 κΈ€

  • νƒœκ·Έ

    zustand
    TailwindCSS
    js
    λ°±μ€€
    Baekjoon
    TypeScript
    modal
    ν•œμž…ν¬κΈ°λ‘œ μž˜λΌλ¨ΉλŠ” νƒ€μž…μŠ€ν¬λ¦½νŠΈ
    issue
    ν•œμž…ν¬κΈ°λ‘œμž˜λΌλ¨ΉλŠ”νƒ€μž…μŠ€ν¬λ¦½νŠΈ
    JavaScript
    what i learn
    μ½”λ”©ν…ŒμŠ€νŠΈ
    Study
    Node.js
    Algorithm
    μžλ°”μŠ€ν¬λ¦½νŠΈ
    μ•Œκ³ λ¦¬μ¦˜
    media-query
    css
  • 졜근 λŒ“κΈ€

  • 졜근 κΈ€

  • hELLOΒ· Designed Byμ •μƒμš°.v4.10.3
nuew
Safariμ—μ„œ 비동기 처리 ν›„ ν˜ΈμΆœν•˜λŠ” window.open() μš°νšŒν•΄μ„œ ν•΄κ²°
μƒλ‹¨μœΌλ‘œ

ν‹°μŠ€ν† λ¦¬νˆ΄λ°”