File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
docs/.vitepress/theme/components Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ const loaded = ref(false)
2424
2525async function create() {
2626 // @ts-expect-error Global variable
27+ if (! window .twttr ?.widgets ?.createTweet )
28+ return
29+ // @ts-expect-error Global variable
2730 await window .twttr .widgets .createTweet (
2831 props .id .toString (),
2932 tweet .value ,
@@ -37,7 +40,7 @@ async function create() {
3740
3841if (isClient ) {
3942 // @ts-expect-error Global variable
40- if (window ?.twttr ?.widgets ) {
43+ if (window ?.twttr ?.widgets ?. createTweet ) {
4144 onMounted (create )
4245 }
4346 else {
Original file line number Diff line number Diff line change @@ -22,7 +22,14 @@ const tweet = ref<HTMLElement | null>()
2222const loaded = ref (false )
2323const tweetNotFound = ref (false )
2424
25- onMounted (async () => {
25+ async function create(retries = 10 ) {
26+ // @ts-expect-error global
27+ if (! window .twttr ?.widgets ?.createTweet ) {
28+ if (retries <= 0 )
29+ return console .error (' Failed to load Twitter widget after 10 retries.' )
30+ setTimeout (() => create (retries - 1 ), 1000 )
31+ return
32+ }
2633 // @ts-expect-error global
2734 const element = await window .twttr .widgets .createTweet (
2835 props .id .toString (),
@@ -36,6 +43,10 @@ onMounted(async () => {
3643 loaded .value = true
3744 if (element === undefined )
3845 tweetNotFound .value = true
46+ }
47+
48+ onMounted (() => {
49+ create ()
3950})
4051 </script >
4152
You can’t perform that action at this time.
0 commit comments