I’m showing users tweets given some server-cached information. The template looks like this (underscore.js syntax):
<%- document.text %>
—<%- url.username %>
...
And as soon as the page is loaded, I call this (CoffeeScript syntax, assuming twttr.js is loaded):
blockquote = @$('blockquote')[0]
id = blockquote.getAttribute('data-tweet-id')
twttr.widgets.createTweetEmbed id, blockquote.parentNode, ->
$(blockquote).remove()
This correctly replaces the blockquote with the tweet.
However, if I remove the DOM element (the whole thing, plus its parent) from the page before Twitter’s server responds with the tweet JSON, I get an icky error with this stack trace:
Uncaught TypeError: Cannot read property 'display' of undefined widgets.js:35
(anonymous function) widgets.js:35
k.aug.callIfSandboxReady widgets.js:33
k.aug.callsWhenSandboxReady widgets.js:33
t.fetchAndRender.l.tweets.complete widgets.js:35
b widgets.js:29
(anonymous function) tweets.json:1
I can’t see any way of catching the error, as my code isn’t throwing it. My app seems stable enough, but it’s frustrating to debug.
Can I (or Twitter) solve this problem? I’m hoping it’s an easy fix somewhere…