Skip to content

Commit

Permalink
fix: cleanup listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed Jul 28, 2023
1 parent 146c108 commit 1076067
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/app/preview/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,21 @@ export default function PreviewPage() {
targinOrigin = decodeURIComponent(targinOrigin)
window.opener.postMessage('Preview Page Ready', targinOrigin)

window.addEventListener(
'message',
debounce((e) => {
if (e.origin !== targinOrigin) {
return
}

const parsedData = JSON.parse(e.data)

if (parsedData.type === 'preview') {
jotaiStore.set(previewDataAtom, simpleCamelcaseKeys(parsedData.data))
}
}, 100),
)
const handler = debounce((e) => {
if (e.origin !== targinOrigin) {
return
}

const parsedData = JSON.parse(e.data)

if (parsedData.type === 'preview') {
jotaiStore.set(previewDataAtom, simpleCamelcaseKeys(parsedData.data))
}
}, 100)
window.addEventListener('message', handler)
return () => {
window.removeEventListener('message', handler)
}
}, [])

const previewData = useAtomValue(previewDataAtom)
Expand Down

1 comment on commit 1076067

@vercel
Copy link

@vercel vercel bot commented on 1076067 Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

shiro-innei.vercel.app
shiro-git-main-innei.vercel.app
springtide.vercel.app
innei.in

Please sign in to comment.