diff --git a/src/components/text-editor/text-editor.stories.tsx b/src/components/text-editor/text-editor.stories.tsx index 9cbfd6e9dc..df8bc4361e 100644 --- a/src/components/text-editor/text-editor.stories.tsx +++ b/src/components/text-editor/text-editor.stories.tsx @@ -205,21 +205,25 @@ export const WithLinkPreviews = () => { const [value, setValue] = useState( EditorState.createWithContent(ContentState.createFromText("www.sage.com")) ); + const firstRender = useRef(false); const previews = useRef([]); const removeUrl = (reportedUrl: string | undefined) => { previews.current = previews.current.filter( (preview) => reportedUrl !== preview.props.url ); }; - previews.current.push( - removeUrl(urlString)} - title="This is an example of a title" - url="https://www.sage.com" - description="Captain, why are we out here chasing comets? I'd like to think that I haven't changed those things, sir. Computer, lights up! Not if I weaken first. Damage report! Yesterday I did not know how to eat gagh. The Federation's gone; the Borg is everywhere! We know you're dealing in stolen ore. But I wanna talk about the assassination attempt on Lieutenant Worf. Our neural pathways have become accustomed to your sensory input patterns. Wouldn't that bring about chaos?" - key="key - 1" - /> - ); + if (!firstRender.current) { + firstRender.current = true; + previews.current.push( + removeUrl(urlString)} + title="This is an example of a title" + url="https://www.sage.com" + description="Captain, why are we out here chasing comets? I'd like to think that I haven't changed those things, sir. Computer, lights up! Not if I weaken first. Damage report! Yesterday I did not know how to eat gagh. The Federation's gone; the Borg is everywhere! We know you're dealing in stolen ore. But I wanna talk about the assassination attempt on Lieutenant Worf. Our neural pathways have become accustomed to your sensory input patterns. Wouldn't that bring about chaos?" + key="key - 1" + /> + ); + } const checkValidDomain = (url: string) => { const domainsWhitelist = [".com", ".co.uk", ".org", ".net"]; const result = domainsWhitelist.filter((domain) => url.endsWith(domain)) @@ -228,8 +232,7 @@ export const WithLinkPreviews = () => { }; const addUrl = (reportedUrl: string) => { if ( - !previews.current.filter((preview) => reportedUrl === preview.props.url) - .length && + !previews.current.some((preview) => reportedUrl === preview.props.url) && checkValidDomain(reportedUrl) ) { const previewConfig = {