In the 13th century, a Belgian nun named Juliana of Liege urged the Church leadership to institute a feast in honor of the Most Blessed Sacrament on the Thursday following Trinity Sunday. The feast of Corpus Christi was eventually established as a universal feast by 1264, and soon after the feast was given an "octave," meaning that the spiritual themes celebrated on Corpus Christi would remain the primary focus of the Church's liturgy for a total of eight days.
This was the case for many centuries, and during the 17th century, St. Margaret Mary Alocque had a private vision in which Jesus revealed his heart to her and said, "I ask thee that the first Friday after the octave of Corpus Christi be set apart as a special feast to honor My Heart." It is recorded that she had this vision during Eucharistic adoration, with the Blessed Sacrament exposed on the altar.
This wasn't completely fulfilled until 1856 when Pope Pius IX established the feast of the Sacred Heart on the universal Roman calendar, fixing it on the day following the octave of Corpus Christi. The feast of the Sacred Heart remains on this day, even though the octave of Corpus Christi is no longer celebrated, and the Solemnity of Corpus Christi is transferred to the Sunday after Trinity Sunday in the United States.
It is fitting that the Church would have meditated on the gift of the Blessed Sacrament for eight days, spiritually preparing oneself to honor the Heart of Jesus. The two are intimately linked, as an article on Catholic Exchange points out.
The two devotions—to the Sacred Heart and to the Eucharist—are closely connected. They call upon one another and, we may even say, they require each other. The Sacred Heart explains the mystery of the love of Jesus by which He becomes bread in order to nourish us with His substance, while in the Eucharist we have the real presence of this same Heart, living in our midst. It is wonderful to contemplate the Heart of Jesus as the symbol of His infinite love, but it is even more wonderful to find Him always near us in the Sacrament of the altar.
Jesus himself asked St. Margaret Mary to promote both the feast of the Sacred Heart and Eucharistic adoration, making the connection very clear. It is in the Eucharistic host that we can find the Heart of Jesus, beating and pouring itself out upon us.
It is not a coincidence that the feast of the Sacred Heart falls so near to the feast of Corpus Christi, as the celebration of one naturally leads to the other.