justinmahar / react-social-media-embed

📰 Easily embed social media posts from Facebook, Instagram, LinkedIn, Pinterest, TikTok, X (Twitter), and YouTube in React.
https://justinmahar.github.io/react-social-media-embed/
MIT License
214 stars 30 forks source link

InstagramEmbed does not load inside Netlify CMS preview #20

Closed miensol closed 1 year ago

miensol commented 1 year ago

In the Netlify CMS app, a preview is rendered inside an iframe. When we use InstagramEmbed as a custom component with MDX the JS script ('//www.instagram.com/embed.js') is attached to the iframe host window/document.

To alleviate any issues with the Netlify CMS preview rendering one can access the iframe's window and document. However, for InstagramEmbed to use it we would need the ability to pass in window and document.

justinmahar commented 1 year ago

Heck yeah. Working on this now.

justinmahar commented 1 year ago

@miensol Thanks for the PR. I expanded on this an added iframe support for Facebook and TikTok.

The API is slightly different from how you implemented it. You need to provide a webAPIs prop that contains window and document. Like so: webAPIs={{window: myWin, document: myDoc}}

Thanks for opening the issue and the PR! Let me know how that works for you.

npm i react-social-media-embed@latest
miensol commented 1 year ago

Thanks for such prompt action!

You're right, I didn't notice that other components use window/document directly as well.

I like the idea of grouping the 2 props i.e. window and document into a single object/type.

I wonder though if there's a more intuitive name for that pair. I mean more intuitive than webAPIs.

For example react-frame-component refers to them as frame. WDYT?

justinmahar commented 1 year ago

I like it. Let's ship it.

justinmahar commented 1 year ago

Done. New prop is frame, like so: frame={{window: myWin, document: myDoc}}. Also renamed the hook to useFrame and updated the README.

npm i react-social-media-embed@latest

Give that a shot and if it's all good we can close this issue.

miensol commented 1 year ago

Awesome! You rock 😎

justinmahar commented 1 year ago

So do you 🤘 Thanks for working on this with me!