@primer/gatsby-theme-doctocat 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @primer/gatsby-theme-doctocat
2
2
 
3
+ ## 4.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`6c4da9e`](https://github.com/primer/doctocat/commit/6c4da9e5787862460972b2af75a27e5909093a05) [#498](https://github.com/primer/doctocat/pull/498) Thanks [@colebemis](https://github.com/colebemis)! - Fix live examples disappearing on hard reload
8
+
3
9
  ## 4.2.0
4
10
 
5
11
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/gatsby-theme-doctocat",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -70,7 +70,6 @@
70
70
  "react-addons-text-content": "^0.0.4",
71
71
  "react-element-to-jsx-string": "^14.0.3",
72
72
  "react-focus-on": "^3.3.0",
73
- "react-frame-component": "^5.2.1",
74
73
  "react-helmet": "^6.1.0",
75
74
  "react-live": "^2.1.2",
76
75
  "react-measure": "^2.3.0",
@@ -1,20 +1,24 @@
1
1
  import React from 'react'
2
- import FrameComponent, {FrameContextConsumer} from 'react-frame-component'
2
+ import ReactDOM from 'react-dom'
3
3
  import {StyleSheetManager} from 'styled-components'
4
4
  import Measure from 'react-measure'
5
5
 
6
6
  function Frame({children}) {
7
7
  const [height, setHeight] = React.useState('auto')
8
+ const [iframeRef, setIframeRef] = React.useState(null)
9
+ const contentDocument = iframeRef ? iframeRef.contentWindow.document : null
10
+
8
11
  return (
9
- <FrameComponent style={{width: '100%', border: 0, borderRadius: 6, height}}>
10
- <FrameContextConsumer>
11
- {({document}) => {
12
- // By default, styled-components injects styles in the head of the page.
13
- // However, styles from the page's head don't apply inside iframes.
14
- // We're using StyleSheetManager to make styled-components inject styles
15
- // into the head of the iframe instead.
16
- return (
17
- <StyleSheetManager target={document.head}>
12
+ // eslint-disable-next-line jsx-a11y/iframe-has-title
13
+ <iframe ref={setIframeRef} style={{width: '100%', border: 0, borderRadius: 6, height}}>
14
+ {
15
+ // By default, styled-components injects styles in the head of the page.
16
+ // However, styles from the page's head don't apply inside iframes.
17
+ // We're using StyleSheetManager to make styled-components inject styles
18
+ // into the head of the iframe instead.
19
+ contentDocument !== null &&
20
+ ReactDOM.createPortal(
21
+ <StyleSheetManager target={contentDocument.head}>
18
22
  <Measure
19
23
  // iframes don't adjust to the height of their content by default.
20
24
  // We're using Measure to calculate the size of the content
@@ -24,11 +28,11 @@ function Frame({children}) {
24
28
  >
25
29
  {({measureRef}) => <div ref={measureRef}>{children}</div>}
26
30
  </Measure>
27
- </StyleSheetManager>
31
+ </StyleSheetManager>,
32
+ contentDocument.body
28
33
  )
29
- }}
30
- </FrameContextConsumer>
31
- </FrameComponent>
34
+ }
35
+ </iframe>
32
36
  )
33
37
  }
34
38