From 79f026b9a95b0fd91693fd943b1b4d66b02f72c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Thu, 26 Aug 2021 10:14:41 +0200 Subject: [PATCH] Making favicon store/restore more robust (#1093) --- mattermost-plugin/webapp/src/index.tsx | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/mattermost-plugin/webapp/src/index.tsx b/mattermost-plugin/webapp/src/index.tsx index 3d947024e..1bf0408e4 100644 --- a/mattermost-plugin/webapp/src/index.tsx +++ b/mattermost-plugin/webapp/src/index.tsx @@ -1,13 +1,12 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React, {useEffect} from 'react' +import React, {useEffect, useState} from 'react' import {Store, Action} from 'redux' import {Provider as ReduxProvider} from 'react-redux' import {useHistory} from 'mm-react-router-dom' import {GlobalState} from 'mattermost-redux/types/store' import {getTheme} from 'mattermost-redux/selectors/entities/preferences' -import {getChannelByName} from 'mattermost-redux/selectors/entities/channels' const windowAny = (window as any) windowAny.baseURL = '/plugins/focalboard' @@ -33,6 +32,8 @@ import {PluginRegistry} from './types/mattermost-webapp' import './plugin.scss' const MainApp = () => { + const [faviconStored, setFaviconStored] = useState(false) + useEffect(() => { document.body.classList.add('focalboard-body') const root = document.getElementById('root') @@ -49,23 +50,15 @@ const MainApp = () => { }, []) useEffect(() => { - const oldLink = document.querySelector("link[rel*='icon']") as HTMLLinkElement - if (!oldLink) { + const oldLinks = document.querySelectorAll("link[rel*='icon']") as NodeListOf + if (!oldLinks) { return () => null } + setFaviconStored(true) - const restoreData = { - type: oldLink.type, - rel: oldLink.rel, - href: oldLink.href, - } return () => { document.querySelectorAll("link[rel*='icon']").forEach((n) => n.remove()) - const link = document.createElement('link') as HTMLLinkElement - link.type = restoreData.type - link.rel = restoreData.rel - link.href = restoreData.href - document.getElementsByTagName('head')[0].appendChild(link) + oldLinks.forEach((link) => document.getElementsByTagName('head')[0].appendChild(link)) } }, []) @@ -73,7 +66,7 @@ const MainApp = () => {
- + {faviconStored && }