talkjs/country-flag-emoji-polyfill

0.1.5 breaks Next.js apps - add README note on typeof window check

Closed this issue · 6 comments

0.1.4:

polyfillCountryFlagEmojis()

0.1.5:

Make sure to check for window if doing server side rendering.
if (typeof window !== 'undefined') polyfillCountryFlagEmojis()

Or add window check in the code, just one line needed I think.

Thanks for your report.

I'm confused that it worked at all in 0.1.4. I think it would've errored out right when you imported the library, no? Reading this code sure makes it seem so. Can you confirm that this is true?

I think it would've errored out right when you imported the library, no? Reading this code sure makes it seem so.

I'm guessing it throws inside the try catch, before ctx is set, then returns early.

ahyes, ofc. thanks. gross, but i guess it works :)

i remember having to do hacks to avoid that in our work setup but maybe our work setup is particularly quirky in this regard :)

anyway! i published a 0.1.6 which should fix this by simply returning false when window is undefined

can you confirm that it solves matters adequately?

Fixed now in my Next.js app