-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: fix using StyleProvider
with Iframe
#38447
Conversation
// export const _iframe = () => { | ||
// const iFrameRef = useRef( null ); | ||
|
||
// const redText = css` | ||
// color: red; | ||
// `; | ||
// const blueText = css` | ||
// color: blue; | ||
// `; | ||
|
||
// return ( | ||
// <Iframe ref={ iFrameRef }> | ||
// <Example args={ [ redText ] }>This text should be red</Example> | ||
// <StyleProvider document={ iFrameRef.current?.contentDocument }> | ||
// <Example args={ [ blueText ] }> | ||
// This text should be blue | ||
// </Example> | ||
// </StyleProvider> | ||
// </Iframe> | ||
// ); | ||
// }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solution attempt no. 1 (manually getting the Iframe
's contentDocument
and passing it to StyleProvider
)
// export const _iframe = () => { | ||
// const redText = css` | ||
// color: red; | ||
// `; | ||
// const blueText = css` | ||
// color: blue; | ||
// `; | ||
|
||
// const Content = ( { iframeDocument } ) => ( | ||
// <> | ||
// <Example args={ [ redText ] }>This text should be red</Example> | ||
// <StyleProvider document={ iframeDocument }> | ||
// <Example args={ [ blueText ] }> | ||
// This text should be blue | ||
// </Example> | ||
// </StyleProvider> | ||
// </> | ||
// ); | ||
|
||
// return ( | ||
// <Iframe> | ||
// <Content /> | ||
// </Iframe> | ||
// ); | ||
// }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solution no. 2: modify the Iframe
component to pass the iframeDocument
prop to its children (see changes in packages/block-editor/src/components/iframe/index.js
)
export const _iframe = () => { | ||
const redText = css` | ||
color: red; | ||
`; | ||
const blueText = css` | ||
color: blue; | ||
`; | ||
|
||
return ( | ||
<Iframe> | ||
<Example args={ [ redText ] }>This text should be red</Example> | ||
<StyleProvider document={ document } whichOne="internal"> | ||
<Example args={ [ blueText ] }> | ||
This text should be blue | ||
</Example> | ||
</StyleProvider> | ||
</Iframe> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solution no. 3 (currently WIP and not working): instead of adding the fix to the "consumer" code, try to fix the issue directly in StyleProvider
by using React's Context to store the correct document / head and re-use it in children components.
Size Change: +60 B (0%) Total Size: 1.14 MB
ℹ️ View Unchanged
|
862aa01
to
9bdd098
Compare
Closing this PR after having decided, together with @sarayourfriend , that the pattern that we were trying to fix (i.e. We also gained more insights on what could be the problem behind #35619 (comment) — I'm going to open a PR in the upcoming days with more details about that. |
Description
WIP
For context, see #37551 (comment) and #35619 (comment)
Testing Instructions
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).