Skip to content

Commit

Permalink
Remove pointless <script> in Tweet component (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis authored Oct 21, 2023
1 parent 01a078a commit 18e7921
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-baboons-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astro-community/astro-embed-twitter": patch
---

Remove unused JavaScript from Tweet component
26 changes: 0 additions & 26 deletions packages/astro-embed-twitter/Tweet.astro
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,3 @@ const tweet = await fetchTweet(id);
---

{tweet && <astro-embed-tweet set:html={tweet.html} />}

<script>
type ElementList = ReturnType<typeof document.querySelectorAll>;

// Based on https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/client/visible.ts
const onVisible = <T extends ElementList>(nodes: T, callback: () => void) => {
const io = new IntersectionObserver((entries) => {
for (const { isIntersecting } of entries) {
if (!isIntersecting) continue;
// As soon as we hydrate, disconnect this IntersectionObserver.
io.disconnect();
callback();
break; // Break loop on first match.
}
});
for (const node of nodes) io.observe(node);
};

const embeds = document.querySelectorAll('astro-embed-tweet');
onVisible(embeds, () => {
const script = document.createElement('script');
script.setAttribute('defer', '');
script.setAttribute('src', 'https://platform.twitter.com/widgets.js');
// document.body.append(script);
});
</script>

0 comments on commit 18e7921

Please sign in to comment.