Skip to content

Commit

Permalink
Add a fallback strategy for IE11
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Abreu committed Sep 6, 2020
1 parent 3689f3e commit e49e135
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions react/start/runtime.ts
@@ -1,3 +1,17 @@
const getValue = (element: HTMLTemplateElement) => {
if (typeof element.content === 'undefined') {
return element.innerHTML
}

let value = ''
const childNodes = element.content.childNodes
for (let i = 0; i < childNodes.length; i++) {
const node = childNodes[i]
value += node.nodeValue
}
return value
}

export const loadRuntimeJSONs = () => {
const scripts = window?.document?.querySelectorAll<HTMLTemplateElement>(
'template[data-type="json"]'
Expand All @@ -10,12 +24,7 @@ export const loadRuntimeJSONs = () => {
(script) =>
new Promise((resolve) => {
setTimeout(() => {
let value = ''
const childNodes = script.content.childNodes
for (let i = 0; i < childNodes.length; i++) {
const node = childNodes[i]
value += node.nodeValue
}
const value = getValue(script)
setTimeout(() => {
;(window as any)[script.id] = JSON.parse(value)
resolve()
Expand Down

0 comments on commit e49e135

Please sign in to comment.