| 1 |
import React from 'react'; |
| 2 |
import { leadinPluginVersion, pluginPath } from '../../constants/leadinConfig'; |
| 3 |
import { useRefEffect } from '@wordpress/compose'; |
| 4 |
|
| 5 |
function StylesheetErrorBondary({ children }: React.PropsWithChildren) { |
| 6 |
const ref = useRefEffect(element => { |
| 7 |
const { ownerDocument } = element; |
| 8 |
if ( |
| 9 |
ownerDocument && |
| 10 |
!ownerDocument.getElementById('leadin-gutenberg-css') |
| 11 |
) { |
| 12 |
const link = ownerDocument.createElement('link'); |
| 13 |
link.id = 'leadin-gutenberg-css'; |
| 14 |
link.rel = 'stylesheet'; |
| 15 |
link.href = `${pluginPath}/build/gutenberg.css?ver=${leadinPluginVersion}`; |
| 16 |
ownerDocument.head.appendChild(link); |
| 17 |
} |
| 18 |
}, []); |
| 19 |
|
| 20 |
return <div ref={ref}>{children}</div>; |
| 21 |
} |
| 22 |
|
| 23 |
export default StylesheetErrorBondary; |
| 24 |
|