Fixed JavaScript and CSS evaluation on instant loading

This commit is contained in:
squidfunk 2020-03-09 16:46:22 +01:00
parent 6daac21f65
commit ea29135841
3 changed files with 6 additions and 5 deletions

View File

@ -46,7 +46,8 @@ import {
observeOn, observeOn,
take, take,
shareReplay, shareReplay,
share share,
skip
} from "rxjs/operators" } from "rxjs/operators"
import { import {
@ -347,7 +348,7 @@ export function initialize(config: unknown) {
/* Resolve relative links for stability */ /* Resolve relative links for stability */
for (const selector of [ for (const selector of [
`link[rel="shortcut icon"]`, `link[rel="shortcut icon"]`,
`link[rel="stylesheet"]` // `link[rel="stylesheet"]` // reduce style computations
]) ])
for (const el of getElements<HTMLLinkElement>(selector)) for (const el of getElements<HTMLLinkElement>(selector))
el.href = el.href el.href = el.href

View File

@ -64,8 +64,8 @@ export function patchScripts(
for (const el of els) { for (const el of els) {
if (el.src || /(^|\/javascript)$/i.test(el.type)) { if (el.src || /(^|\/javascript)$/i.test(el.type)) {
const script = document.createElement("script") const script = document.createElement("script")
const key = el.src ? "src" : "innerText" const key = el.src ? "src" : "textContent"
script[key] = el[key] script[key] = el[key]!
el.replaceWith(script) el.replaceWith(script)
} }
} }

View File

@ -64,7 +64,7 @@ let lang: Record<string, string>
export function translate(key: TranslateKey, value?: string): string { export function translate(key: TranslateKey, value?: string): string {
if (typeof lang === "undefined") { if (typeof lang === "undefined") {
const el = getElementOrThrow("#__lang") const el = getElementOrThrow("#__lang")
lang = JSON.parse(el.innerText) lang = JSON.parse(el.textContent!)
} }
if (typeof lang[key] === "undefined") { if (typeof lang[key] === "undefined") {
throw new ReferenceError(`Invalid translation: ${key}`) throw new ReferenceError(`Invalid translation: ${key}`)