Truth for life fix

This commit is contained in:
nmemmert
2026-06-04 09:23:11 -04:00
parent cb78b6522d
commit 20397960d6
+10 -23
View File
@@ -1059,36 +1059,23 @@ function HomepageNewsletterSection() {
type TflWidgetType = 'audiodevo' | 'abdevotional'
function TruthForLifeWidget({ type = 'audiodevo' }: { type?: TflWidgetType }) {
const containerId = `tfl-syndicate-container-${type}`
useEffect(() => {
// Remove any previous instance of this script to allow re-init on re-mount
const existingScript = document.getElementById('tfl-syn-script-' + type)
if (existingScript) existingScript.remove()
// TFL's script looks for #tfl-syndicate-container synchronously when it loads.
// The div is already in the DOM by the time this effect runs, so we just
// inject the script and it will find and populate the container.
const existing = document.getElementById('tfl-syn-script')
if (existing) existing.remove()
// Clear the container so the widget can repopulate it
const container = document.getElementById(containerId)
const container = document.getElementById('tfl-syndicate-container')
if (container) container.innerHTML = ''
const script = document.createElement('script')
script.id = 'tfl-syn-script-' + type
script.id = 'tfl-syn-script'
script.src = `https://www.truthforlife.org/static/js/responsive/lib/syndicate.js?type=${type}&id=458890`
script.type = 'text/javascript'
// The TFL script looks for #tfl-syndicate-container by ID — temporarily
// rename our container to match, then rename back after the script fires
if (container) container.id = 'tfl-syndicate-container'
script.async = true
document.body.appendChild(script)
// Restore the namespaced id after a tick so React doesn't lose track
const restore = setTimeout(() => {
const el = document.getElementById('tfl-syndicate-container')
if (el) el.id = containerId
}, 2000)
return () => {
clearTimeout(restore)
script.remove()
}
return () => { script.remove() }
}, [type])
return (
@@ -1101,7 +1088,7 @@ function TruthForLifeWidget({ type = 'audiodevo' }: { type?: TflWidgetType }) {
<p className="tfl-attribution">
Teaching from <a href="https://www.truthforlife.org" target="_blank" rel="noreferrer" className="tfl-link">Truth For Life</a> with Alistair Begg
</p>
<div id={containerId} className="tfl-widget-wrap" />
<div id="tfl-syndicate-container" className="tfl-widget-wrap" />
</div>
</section>
)