-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from prezly/fix/qrf-113-embeds-vanish-in-edito…
…r-in-published [QRF-113] Fix - Iframely Embeds not visible on first page load
- Loading branch information
Showing
30 changed files
with
52 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.idea/ | ||
.yalc/ | ||
.history | ||
build/ | ||
coverage/ | ||
|
Binary file modified
BIN
+3.86 KB
(100%)
.loki/reference/chrome_iphone7_Elements_Gallery_Contained_Small_Padding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+49.9 KB
(100%)
.loki/reference/chrome_iphone7_Elements_Gallery_Expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.65 KB
(100%)
.loki/reference/chrome_iphone7_Elements_Gallery_Full_Width.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.54 KB
(100%)
.loki/reference/chrome_iphone7_Elements_Image_Left_Aligned.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.53 KB
(100%)
.loki/reference/chrome_iphone7_Elements_Image_Right_Aligned.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+86.4 KB
(100%)
.loki/reference/chrome_iphone7_Elements_Image_Width_100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+0 Bytes
(100%)
.loki/reference/chrome_laptop_Elements_Contact_Press_Contacts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.71 KB
(100%)
.loki/reference/chrome_laptop_Elements_Gallery_Contained_Small_Padding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-655 Bytes
(100%)
.loki/reference/chrome_laptop_Elements_Gallery_Expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.98 KB
(99%)
.loki/reference/chrome_laptop_Elements_Gallery_Full_Width.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.74 KB
(100%)
.loki/reference/chrome_laptop_Elements_Image_Left_Aligned.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.84 KB
(100%)
.loki/reference/chrome_laptop_Elements_Image_Right_Aligned.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1017 Bytes
(100%)
.loki/reference/chrome_laptop_Elements_Image_Width_45.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.81 KB
(100%)
.loki/reference/chrome_narrow_Elements_Gallery_Contained_Small_Padding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+39.4 KB
(100%)
.loki/reference/chrome_narrow_Elements_Gallery_Expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.17 KB
(100%)
.loki/reference/chrome_narrow_Elements_Gallery_Full_Width.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-95 Bytes
(100%)
.loki/reference/chrome_narrow_Elements_Image_Left_Aligned.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-151 Bytes
(100%)
.loki/reference/chrome_narrow_Elements_Image_Right_Aligned.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+167 Bytes
(100%)
.loki/reference/chrome_narrow_Elements_Image_Width_45.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,49 @@ | ||
import React, { FunctionComponent, useEffect, useRef } from 'react'; | ||
import { useSyncedRef } from '@react-hookz/web'; | ||
import { injectHtmlMarkup } from '../lib'; | ||
import React, { HTMLAttributes, ScriptHTMLAttributes, useEffect } from 'react'; | ||
|
||
interface Props { | ||
interface Props extends HTMLAttributes<HTMLDivElement> { | ||
html: string; | ||
id?: string; | ||
className?: string; | ||
onError: () => void; | ||
} | ||
|
||
export const HtmlInjection: FunctionComponent<Props> = (props) => { | ||
const { html, className, id } = props; | ||
const freshProps = useSyncedRef<Props>(props); | ||
const ref = useRef<HTMLDivElement>(null); | ||
export function HtmlInjection(props: Props) { | ||
const { html, onError, ...attrs } = props; | ||
|
||
useScripts(html, onError); | ||
|
||
return <div {...attrs} dangerouslySetInnerHTML={{ __html: html }} />; | ||
} | ||
|
||
function useScripts(html: Props['html'], onError: Props['onError']) { | ||
useEffect(() => { | ||
if (ref.current) { | ||
injectHtmlMarkup({ | ||
html, | ||
onError: () => freshProps.current.onError(), | ||
target: ref.current, | ||
}); | ||
} | ||
const container = document.createElement('div'); | ||
container.innerHTML = html; | ||
|
||
const scripts: ScriptHTMLAttributes<HTMLScriptElement>[] = Array.from( | ||
container.getElementsByTagName('script'), | ||
).map((script) => { | ||
return Array.from(script.attributes).reduce((agg, { name, value }) => ({ ...agg, [name]: value }), {}); | ||
}); | ||
|
||
container.remove(); | ||
|
||
scripts.forEach((attributes) => { | ||
if (attributes.src && document.querySelector(`script[src="${attributes.src}"]`)) { | ||
return; | ||
} | ||
|
||
const script = document.createElement('script'); | ||
setScriptAttributes(script, attributes); | ||
|
||
script.addEventListener('error', onError); | ||
document.body.appendChild(script); | ||
}); | ||
|
||
iframely?.load(); | ||
|
||
return; | ||
}, [html]); | ||
} | ||
|
||
return <div id={id} className={className} ref={ref} />; | ||
}; | ||
function setScriptAttributes(script: HTMLScriptElement, attributes: ScriptHTMLAttributes<HTMLScriptElement>): void { | ||
Object.entries(attributes).forEach(([name, value]) => script.setAttribute(name, value)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,8 @@ | |
border: 1px solid $color-error; | ||
border-radius: $border-radius-base; | ||
} | ||
|
||
blockquote { | ||
border-left: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
interface Iframely { | ||
load(): void; | ||
} | ||
|
||
declare const iframely: Iframely | undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters