From 1ed0e97b103cb0b893e6533c95f1ecef25dac132 Mon Sep 17 00:00:00 2001 From: Simon Jockers <449739+sjockers@users.noreply.github.com> Date: Mon, 23 Feb 2026 18:32:07 +0100 Subject: [PATCH 01/10] Log debug information --- .../datawrapper-switcher/DatawrapperSwitcher.svelte | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte index 0732296f..34c6b8a0 100644 --- a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte +++ b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte @@ -21,7 +21,10 @@
- Datawrapper switcher to be rendered here: +
{JSON.stringify({ labels, ids, fixedHeight, layout }, null, 2)}
+ + -
+
From 3ae9f860eea22bd62d5ce4d395833181108b8a41 Mon Sep 17 00:00:00 2001 From: Simon Jockers <449739+sjockers@users.noreply.github.com> Date: Wed, 25 Feb 2026 11:10:29 +0100 Subject: [PATCH 02/10] Refactor getDataFromUrl (less specific to domains, add error logging) --- .../src/lib/utils/getDataFromUrl.ts | 29 ++++++++----------- .../DatawrapperSwitcher.svelte | 6 ++++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/sophora-components/src/lib/utils/getDataFromUrl.ts b/sophora-components/src/lib/utils/getDataFromUrl.ts index 9448278c..ac1fe0fa 100644 --- a/sophora-components/src/lib/utils/getDataFromUrl.ts +++ b/sophora-components/src/lib/utils/getDataFromUrl.ts @@ -1,21 +1,16 @@ export default function getDataFromUrl(target: HTMLElement): Record { - let url: URL; - if ( - // SvelteKit DEV mode, preview server, or static hosting: - import.meta.env.DEV || - window.location.origin === 'http://localhost:4173' || - window.location.origin === 'https://static.datenhub.net' || - window.location.href.includes('apidata.googleusercontent.com') || - window.location.href.includes('storage.googleapis.com') - ) { + const parent = target.parentNode?.parentNode as HTMLElement | null; + + // Default: Embedded mode – use URL used to embed the component + // `data-url` is the embeds the grandparent element, provided by Sophora + let embedURL = parent?.dataset.url; + + if (!embedURL) { // Preview mode – use URL of current page - url = new URL(window.location.href); - } else { - // Embedded mode – use URL used to embed the component - // `data-url` is set on the grandparent element, provided by Sophora - const parent = target.parentNode?.parentNode as HTMLElement | null; - url = new URL(parent?.dataset.url || ''); + embedURL = window?.location.href; } - const params: Record = Object.fromEntries(url.searchParams); - return params; + + return URL.canParse(embedURL) + ? Object.fromEntries(new URL(embedURL).searchParams.entries()) + : (console.error('Could not parse Embed-URL:', embedURL), {}); } diff --git a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte index 34c6b8a0..10d27c1f 100644 --- a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte +++ b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte @@ -10,12 +10,16 @@ let fixedHeight = $state(null); let layout = $state('auto'); + let url = $state(''); + onMount(() => { const entries = getDataFromUrl(root); labels = entries.labels.split(',') || []; ids = entries.ids.split(',') || []; fixedHeight = entries.fixedHeight || null; layout = entries.layout || 'auto'; + + url = window.location?.href; }); @@ -23,6 +27,8 @@

Datawrapper switcher to be rendered here:

{JSON.stringify({ labels, ids, fixedHeight, layout }, null, 2)}
+
dataset url: {root?.parentNode?.parentNode?.dataset.url || 'n/a'}
+
actual url: {url || 'n/a'}
+ /> - +
+ +

Debug Information:

+

data-url: {root?.parentNode?.parentNode?.dataset.url || 'n/a'}

+
+
{JSON.stringify({ labels, ids, fixedHeight, layout }, null, 2)}
+ {#if error} +
{error}
+ {/if} From f9f0bbdc6be4ca622a10374b6a40ec8d40a5767d Mon Sep 17 00:00:00 2001 From: Simon Jockers <449739+sjockers@users.noreply.github.com> Date: Thu, 26 Feb 2026 20:39:53 +0100 Subject: [PATCH 07/10] Show actual page URL in debugging --- .../src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte index 1a0a9d8d..85dcc32c 100644 --- a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte +++ b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte @@ -14,6 +14,8 @@ let error = $state(null); onMount(() => { + url = window?.location.href; + try { const entries = getDataFromUrl(root); labels = entries.labels?.split(',') || []; @@ -57,6 +59,7 @@

Debug Information:

+

actual url: {url || 'n/a'}

data-url: {root?.parentNode?.parentNode?.dataset.url || 'n/a'}


{JSON.stringify({ labels, ids, fixedHeight, layout }, null, 2)}
From 08c4e6143f0290c93711c03b3441f4b7049fa576 Mon Sep 17 00:00:00 2001 From: Simon Jockers <449739+sjockers@users.noreply.github.com> Date: Wed, 25 Mar 2026 17:05:09 +0100 Subject: [PATCH 08/10] Add debug logging --- .../datawrapper-switcher/DatawrapperSwitcher.svelte | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte index 85dcc32c..4141447f 100644 --- a/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte +++ b/sophora-components/src/routes/datawrapper-switcher/DatawrapperSwitcher.svelte @@ -1,7 +1,7 @@