The COVID-19 pandemic has been painful for brick-and-mortar retailers that sell nonessential goods like apparel. Off-price titan TJX Companies (NYSE:TJX) was no exception. After years of steady growth, sales plunged by more than half in the first quarter of the current 2021 fiscal year and still haven't returned to growth.

However, parts of TJX's business are performing extremely well during the pandemic. With vaccines likely to become widely available during 2021, TJX stock has rallied strongly this year. A better-than-expected Q3 earnings report supported further gains, enabling TJX stock to touch an all-time high on Wednesday morning before retreating modestly with the rest of the market.

TJX Chart

TJX stock performance. Data by YCharts.

The sales recovery continues

During the second quarter, TJX's sales trends improved rapidly as the retailer reopened stores. For the full quarter, net sales fell 32%, but comparable sales (excluding closed stores) fell just 3%, reflecting pent-up consumer demand. By the end of the quarter, TJX had reopened most of its stores, with comparable sales trending down 10% to 20%. In August, management projected that sales trends would remain in that range during the third quarter.

However, sales trends strengthened again last quarter. Comp sales (again excluding closed stores) fell a modest 5%, while total sales decreased just 3% year over year to $10.1 billion. That easily surpassed the average analyst estimate of $9.4 billion. The HomeGoods division continued its recent string of outperformance, posting 15% comp sales growth and a 19% surge in total sales. By contrast, the more apparel-focused T.J. Maxx and Marshalls chains suffered a 10% comp sales decline.

The rapid sales recovery enabled TJX to rebuild its profitability in the third quarter. It recorded a 10% pre-tax margin, down modestly from 10.7% a year earlier. Excluding $270 million of pandemic-related costs, TJX's profit margin would have increased significantly. As it was, the company posted earnings per share of $0.71 (including a $0.09 per share benefit from a lower tax rate), up from EPS of $0.68 a year earlier. The analyst consensus had called for EPS of just $0.40.

Impressive cash flow

If anything, TJX's cash flow performance last quarter was even more impressive than its sales and earnings recovery. The retailer generated $4.1 billion of operating cash flow and about $4 billion of free cash flow in the third quarter. Year to date, it has now generated more than $3.8 billion of free cash flow, up by nearly $3 billion compared to the same period last year.

A person with a full shopping cart outside a Marshalls store.

Image source: The TJX Companies.

To be fair, favorable working capital moves -- particularly from delaying some payments to vendors -- boosted TJX's cash flow last quarter. Most of that working capital benefit will reverse next year. Nevertheless, after facing a cash crunch earlier this year, TJX is now swimming in cash, with $10.6 billion on its balance sheet at the end of October.

As a result, the company announced that it plans to reinstate its dividend. Pending board approval, it will in December declare its next dividend of $0.26 per share to be paid out in March 2021. That's 13% higher than TJX's previous dividend rate.

TJX is back on track

In the short term, TJX will continue to face turbulence. For example, about 470 of its 4,574 stores are temporarily closed due to the pandemic (mainly in Europe). Furthermore, while customer traffic has improved, many people still aren't comfortable shopping in stores. Finally, demand for trendy apparel will remain depressed until people start returning to the office and large social events resume.

The eventual end of the pandemic will resolve all of those issues, though. In the meantime, TJX has shown that it can make plenty of money in the current environment, even with sales somewhat below 2019 levels.

Not all of its peers can say the same. In fact, a record number of retail stores are on pace to close in the U.S. this year, including many TJX competitors. That's creating a huge market share opportunity. Given its stellar long-term track record, it's a safe bet that the company will take full advantage, driving its sales and earnings to new heights. Even after reaching a new all-time high this week, TJX stock has plenty of upside for long-term investors.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.