Skip to content

Commit

Permalink
Components: refactor Sandbox to pass exhaustive-deps (#44378)
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 committed Sep 27, 2022
1 parent cbc6e04 commit 8aa2aa2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- `Mobile` updated to ignore `react/exhaustive-deps` eslint rule ([#44207](https://github.com/WordPress/gutenberg/pull/44207)).
- `Popover`: refactor unit tests to TypeScript and modern RTL assertions ([#44373](https://github.com/WordPress/gutenberg/pull/44373)).
- `Sandbox`: updated to satisfy `react/exhaustive-deps` eslint rule ([#44378](https://github.com/WordPress/gutenberg/pull/44378))

## 21.1.0 (2022-09-21)

Expand Down
20 changes: 13 additions & 7 deletions packages/components/src/sandbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,38 @@ export default function Sandbox( {
setHeight( data.height );
}

const { ownerDocument } = ref.current;
const iframe = ref.current;
const { ownerDocument } = iframe;
const { defaultView } = ownerDocument;

// This used to be registered using <iframe onLoad={} />, but it made the iframe blank
// after reordering the containing block. See these two issues for more details:
// https://github.com/WordPress/gutenberg/issues/6146
// https://github.com/facebook/react/issues/18752
ref.current.addEventListener( 'load', tryNoForceSandbox, false );
iframe.addEventListener( 'load', tryNoForceSandbox, false );
defaultView.addEventListener( 'message', checkMessageForResize );

return () => {
ref.current?.removeEventListener(
'load',
tryNoForceSandbox,
false
);
iframe?.removeEventListener( 'load', tryNoForceSandbox, false );
defaultView.addEventListener( 'message', checkMessageForResize );
};
// Ignore reason: passing `exhaustive-deps` will likely involve a more detailed refactor.
// See https://github.com/WordPress/gutenberg/pull/44378
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [] );

useEffect( () => {
trySandbox();
// Ignore reason: passing `exhaustive-deps` will likely involve a more detailed refactor.
// See https://github.com/WordPress/gutenberg/pull/44378
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ title, styles, scripts ] );

useEffect( () => {
trySandbox( true );
// Ignore reason: passing `exhaustive-deps` will likely involve a more detailed refactor.
// See https://github.com/WordPress/gutenberg/pull/44378
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ html, type ] );

return (
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/sandbox/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ function Sandbox( {

useEffect( () => {
updateContentHtml();
// Disable reason: deferring this refactor to the native team.
// see https://github.com/WordPress/gutenberg/pull/41166
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ html, title, type, styles, scripts ] );

useEffect( () => {
Expand Down

0 comments on commit 8aa2aa2

Please sign in to comment.