PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.6.6
LatePoint – Calendar Booking Plugin for Appointments and Events v5.6.6
5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / blocks / src / utils / IframeEmotionCacheProvider.js
latepoint / blocks / src / utils Last commit date
IframeEmotionCacheProvider.js 1 month ago
IframeEmotionCacheProvider.js
31 lines
1 import { useState } from '@wordpress/element';
2 import { useRefEffect } from '@wordpress/compose';
3 import createCache from '@emotion/cache';
4 import { CacheProvider } from '@emotion/react';
5
6 // WordPress 6.9+ renders blocks inside an iframe when every registered block
7 // declares apiVersion >= 3. Emotion's default cache injects <style> tags into
8 // the parent document's <head>, so styled components rendered inside the iframe
9 // appear unstyled. This provider builds an Emotion cache whose container is
10 // the iframe document's <head> and wraps children in <CacheProvider> so all
11 // styled components within it land their CSS in the correct document.
12 export default function IframeEmotionCacheProvider( { children } ) {
13 const [ cache, setCache ] = useState( null );
14
15 const ref = useRefEffect( ( element ) => {
16 const doc = element.ownerDocument;
17 setCache(
18 createCache( {
19 key: 'latepoint-block',
20 container: doc.head,
21 } )
22 );
23 }, [] );
24
25 return (
26 <div ref={ ref } className="latepoint-block-iframe-cache-host">
27 { cache && <CacheProvider value={ cache }>{ children }</CacheProvider> }
28 </div>
29 );
30 }
31