In chapter 19 against Rui the dance and the sanguine explosion take place, do they have a past reference? or is he a deus ex author's error? I need your help
Is Tanjiro using the fire god's breath dance and Nezuko using his ability a deus ex machine? Does it have foreshadow?
It could be considered a Deus ex machina. To quote from its definition:
...a plot device whereby a seemingly unsolvable problem in a story is suddenly and abruptly resolved by an unexpected and unlikely occurrence.
The 'unsolvable problem' here would be the fight between Rui and Tanjiro since the latter was on the verge of losing to the former's seemingly overwhelming strength. Tanjiro then discovers a new skill using a different breathing technique and while it may not have 'abruptly resolved' the problem, it was 'unexpected and unlikely' since he was only shown to use Water breathing techniques and it was enough to buy time for reinforcements to arrive, as seen in Episode 20.
But was this an error? I don't think so. This event was meant as the beginning to unraveling of Tanjiro's past. Personally, I think it was a good way since it makes you curious about the background of Tanjiro's family, whether they were really just a family who makes charcoal or was there something more since his father seems to know breathing techniques. Was there foreshadowing before this? None. Rather, this is the foreshadowing to something later on in the storyline. All the unanswered questions from this part will eventually be answered later on as the story progresses. You can read the manga or wait for the anime to adapt everything.
There isn't a ton of foreshadowing, but I would argue it's not an error or bad storytelling. I think it was completely intentional and works well in the story.
We didn't know beforehand that Tanjiro's father passed an ability down to him, but we knew there was more to Tanjiro's father than there seemed. Muzan recognized the hanafuda earrings the first time he and Tanjiro met, which were passed down to Tanjiro from his father. So Tanjiro's father was someone a demon lord would remember, and fear enough to try and kill anyone wearing his earrings. There's also the mystery of Tanjiro's burn scar. We don't find out during the series how he got it, so it's a mystery from his past. It symbolically associates him with fire, which gets us thinking about mysteries in his past related to fire, which eventually leads to the fire dance.
The deus ex machina becomes bad storytelling when it destroys dramatic tension and conflict. I don't think that happens here. Unlocking the fire dance doesn't actually solve any of Tanjiro's problems directly. It doesn't even kill Rui, the enemy he was fighting. At best it keeps the fight going so Rui can't kidnap Nezuko and buys some time for Tomioka to show up and kill off Rui. And unlocking the fire dance sets up future stories. It's a new mystery for Tanjiro to unravel, and also a new challenge for him to figure out how to use it and how to combine it with his water breathing techniques. So I don't think the fire dance needed a ton of foreshadowing. It's not the end of a story, it's the beginning, and I imagine it's explored more deeply as the story goes on (in the manga or in a second season of the anime that maybe hopefully is coming someday).