Skip to content

Commit

Permalink
use DOMParser before injecting Fragments API responses
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jan 6, 2024
1 parent 222efaa commit 40eb1d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@

globalThis.document.getElementById('load-products').addEventListener('click', async () => {
offset = offset += page;

const html = await fetch(`/api/fragment?offset=${offset}&limit=10`).then(resp => resp.text());
const fragment = new DOMParser().parseFromString(html, 'text/html', {
includeShadowRoots: true
});

document.getElementById('load-products-output').insertAdjacentHTML('beforeend', html);
document.getElementById('load-products-output').insertAdjacentHTML('beforeend', fragment.body.innerHTML);
});
});
</script>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
'content-type': 'application/x-www-form-urlencoded'
})
}).then(resp => resp.text());
const fragment = new DOMParser().parseFromString(html, 'text/html', {
includeShadowRoots: true
});

document.getElementById('search-products-output').innerHTML = html;
document.getElementById('search-products-output').innerHTML = fragment.body.innerHTML;
});
});
</script>
Expand Down

0 comments on commit 40eb1d5

Please sign in to comment.