forked from cybrespace/pinafore
fix: logging out results in visible homescreen (#807)
* fix: logging out results in visible homescreen fixes #805 * fixup
This commit is contained in:
parent
d5c0268ef2
commit
c90ad17686
|
@ -1,3 +1,4 @@
|
|||
|
||||
// For perf reasons, this script is run inline to quickly set certain styles.
|
||||
// To allow CSP to work correctly, we also calculate a sha256 hash during
|
||||
// the build process and write it to inline-script-checksum.json.
|
||||
|
@ -7,17 +8,23 @@ import { switchToTheme } from './src/routes/_utils/themeEngine'
|
|||
|
||||
window.__themeColors = process.env.THEME_COLORS
|
||||
|
||||
const hasLocalStorage = testHasLocalStorageOnce()
|
||||
function safeParse (str) {
|
||||
return str === 'undefined' ? undefined : JSON.parse(str)
|
||||
}
|
||||
|
||||
if (hasLocalStorage && localStorage.store_currentInstance && localStorage.store_instanceThemes) {
|
||||
let safeParse = (str) => str === 'undefined' ? undefined : JSON.parse(str)
|
||||
const hasLocalStorage = testHasLocalStorageOnce()
|
||||
const currentInstance = hasLocalStorage &&
|
||||
localStorage.store_currentInstance &&
|
||||
safeParse(localStorage.store_currentInstance)
|
||||
|
||||
if (currentInstance && localStorage.store_instanceThemes) {
|
||||
let theme = safeParse(localStorage.store_instanceThemes)[safeParse(localStorage.store_currentInstance)]
|
||||
if (theme && theme !== 'default') {
|
||||
switchToTheme(theme)
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasLocalStorage || !localStorage.store_currentInstance) {
|
||||
if (!hasLocalStorage || !currentInstance) {
|
||||
// if not logged in, show all these 'hidden-from-ssr' elements
|
||||
let style = document.createElement('style')
|
||||
style.textContent = '.hidden-from-ssr { opacity: 1 !important; }'
|
||||
|
|
|
@ -48,7 +48,7 @@ html{scrollbar-face-color:var(--scrollbar-face-color);scrollbar-track-color:var(
|
|||
</head>
|
||||
<body>
|
||||
<!-- auto-generated w/ build-inline-script.js -->
|
||||
<!-- insert inline script here --><script>!function(){"use strict";let e=document.getElementById("theThemeColor"),t=document.getElementById("theOfflineStyle");function o(){return document.head.querySelector('link[rel=stylesheet][href^="/theme-"]')}window.__themeColors={default:"royalblue",scarlet:"#e04e41",seafoam:"#177380",hotpants:"hotpink",oaken:"saddlebrown",majesty:"blueviolet",gecko:"#4ab92f",ozark:"#5263af",cobalt:"#08439b",sorcery:"#ae91e8",punk:"#e04e41",riot:"hotpink",hacker:"#4ab92f",pitchblack:"#000"};const n=(()=>{try{if(localStorage.setItem("__test__","__test__"),!localStorage.length||"__test__"!==localStorage.getItem("__test__"))return!1;localStorage.removeItem("__test__")}catch(e){return!1}return!0})();if(n&&localStorage.store_currentInstance&&localStorage.store_instanceThemes){let n=e=>"undefined"===e?void 0:JSON.parse(e),r=n(localStorage.store_instanceThemes)[n(localStorage.store_currentInstance)];r&&"default"!==r&&function(n){let r=window.__themeColors[n];e.content=r||window.__themeColors.default,"default"!==n?function(e){let n=o(),r=document.createElement("link");r.rel="stylesheet",r.href=e,r.addEventListener("load",function e(){r.removeEventListener("load",e),n&&document.head.removeChild(n)}),document.head.insertBefore(r,t)}(`/theme-${n}.css`):function(){let e=o();e&&document.head.removeChild(e)}()}(r)}if(!n||!localStorage.store_currentInstance){let e=document.createElement("style");e.textContent=".hidden-from-ssr { opacity: 1 !important; }",document.head.appendChild(e)}if(n&&"true"===localStorage.store_disableCustomScrollbars){document.getElementById("theScrollbarStyle").setAttribute("media","only x")}/mac/i.test(navigator.platform)&&document.documentElement.style.setProperty("--scrollbar-border-radius","50px"),/iP(?:hone|ad|od)/.test(navigator.userAgent)&&document.head.removeChild(document.getElementById("theManifest"))}();
|
||||
<!-- insert inline script here --><script>!function(){"use strict";let e=document.getElementById("theThemeColor"),t=document.getElementById("theOfflineStyle");function o(){return document.head.querySelector('link[rel=stylesheet][href^="/theme-"]')}function n(e){return"undefined"===e?void 0:JSON.parse(e)}window.__themeColors={default:"royalblue",scarlet:"#e04e41",seafoam:"#177380",hotpants:"hotpink",oaken:"saddlebrown",majesty:"blueviolet",gecko:"#4ab92f",ozark:"#5263af",cobalt:"#08439b",sorcery:"#ae91e8",punk:"#e04e41",riot:"hotpink",hacker:"#4ab92f",pitchblack:"#000"};const r=(()=>{try{if(localStorage.setItem("__test__","__test__"),!localStorage.length||"__test__"!==localStorage.getItem("__test__"))return!1;localStorage.removeItem("__test__")}catch(e){return!1}return!0})(),l=r&&localStorage.store_currentInstance&&n(localStorage.store_currentInstance);if(l&&localStorage.store_instanceThemes){let r=n(localStorage.store_instanceThemes)[n(localStorage.store_currentInstance)];r&&"default"!==r&&function(n){let r=window.__themeColors[n];e.content=r||window.__themeColors.default,"default"!==n?function(e){let n=o(),r=document.createElement("link");r.rel="stylesheet",r.href=e,r.addEventListener("load",function e(){r.removeEventListener("load",e),n&&document.head.removeChild(n)}),document.head.insertBefore(r,t)}(`/theme-${n}.css`):function(){let e=o();e&&document.head.removeChild(e)}()}(r)}if(!r||!l){let e=document.createElement("style");e.textContent=".hidden-from-ssr { opacity: 1 !important; }",document.head.appendChild(e)}if(r&&"true"===localStorage.store_disableCustomScrollbars){document.getElementById("theScrollbarStyle").setAttribute("media","only x")}/mac/i.test(navigator.platform)&&document.documentElement.style.setProperty("--scrollbar-border-radius","50px"),/iP(?:hone|ad|od)/.test(navigator.userAgent)&&document.head.removeChild(document.getElementById("theManifest"))}();
|
||||
|
||||
//# sourceMappingURL=/inline-script.js.map</script><!-- end insert inline script here -->
|
||||
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
import { Selector as $ } from 'testcafe'
|
||||
import {
|
||||
addInstanceButton,
|
||||
authorizeInput, emailInput, formError, getFirstVisibleStatus, getUrl, instanceInput, logInToInstanceLink,
|
||||
authorizeInput,
|
||||
emailInput,
|
||||
formError,
|
||||
getFirstVisibleStatus, getOpacity,
|
||||
getUrl,
|
||||
homeNavButton,
|
||||
instanceInput,
|
||||
logInToInstanceLink,
|
||||
mastodonLogInButton,
|
||||
passwordInput,
|
||||
passwordInput, reload,
|
||||
settingsButton,
|
||||
sleep
|
||||
} from '../utils'
|
||||
|
@ -55,6 +62,13 @@ test('Logs in and logs out of localhost:3000', async t => {
|
|||
.expect($('.acct-display-name').innerText).eql('foobar')
|
||||
.click($('button').withText('Log out'))
|
||||
.click($('.modal-dialog button').withText('OK'))
|
||||
.expect($('.main-content').innerText)
|
||||
.contains("You're not logged in to any instances")
|
||||
.expect($('.main-content').innerText).contains("You're not logged in to any instances")
|
||||
.click(homeNavButton)
|
||||
// check that the "hidden from SSR" content is visible
|
||||
.expect(getOpacity('.hidden-from-ssr')()).eql('1')
|
||||
.navigateTo('/')
|
||||
.expect(getOpacity('.hidden-from-ssr')()).eql('1')
|
||||
await reload()
|
||||
await t
|
||||
.expect(getOpacity('.hidden-from-ssr')()).eql('1')
|
||||
})
|
||||
|
|
|
@ -102,6 +102,8 @@ export const goBack = exec(() => window.history.back())
|
|||
|
||||
export const goForward = exec(() => window.history.forward())
|
||||
|
||||
export const reload = exec(() => window.location.reload())
|
||||
|
||||
export const forceOffline = exec(() => window.__forceOnline(false))
|
||||
|
||||
export const forceOnline = exec(() => window.__forceOnline(true))
|
||||
|
@ -110,6 +112,10 @@ export const getComposeSelectionStart = exec(() => composeInput().selectionStart
|
|||
dependencies: { composeInput }
|
||||
})
|
||||
|
||||
export const getOpacity = selector => exec(() => window.getComputedStyle(document.querySelector(selector)).opacity, {
|
||||
dependencies: { selector }
|
||||
})
|
||||
|
||||
export const getCurrentTheme = exec(() => {
|
||||
let themeLink = document.head.querySelector('link[rel=stylesheet][href^="/theme-"]')
|
||||
if (themeLink) {
|
||||
|
|
Loading…
Reference in New Issue