waterfaust
In my experience (on my second water-only fast presently... 1st time 8 days going for 10, now on Day 8 going for 21+) heartburn was always precipitated by thoughts about food and salivating, and by swallowing saliva and air. I have found that spitting out any rush of saliva (perhaps conducive to cleansing in any case) effectively prevented my stomach from making ready for food by producing acids.
Although I have had many bouts of severe heartburn while fasting, I have had NO recurrence for as long as I have been avoiding swallowing any rush of saliva. I'm not highly experienced with fasting, but severe heartburn did curtail my first water-only fast 2 months ago, and I've been most gratified to apparently have full control over my heartburn this time around.
In summary, what's worked for me in preventing heartburn while fasting is:
1) to control/divert my thoughts of food and eating, and
2) to always keep an extra, distinguishable container handy as my cuspidor while indoors. Spitting out saliva is not socially acceptable in my society (USA)- but then again... neither is fasting.
Good luck, good cheer, and good health everyone.