2017 was an incredible year for many solar stocks. The Invesco Solar ETF (NYSEMKT:TAN) was up 52%, while a handful of individual stocks, including First Solar (NASDAQ:FSLR)Enphase Energy (NASDAQ:ENPH), and SolarEdge Technologies (NASDAQ:SEDG) more than doubled in price. 

While Enphase and SolarEdge are once again trouncing the market, 2018 hasn't been so kind to many solar stocks. Shares of First Solar and fellow panel makers SunPower (NASDAQ:SPWR) and Canadian Solar (NASDAQ:CSIQ) are down more than 21% so far, and the Solar ETF has lost 11% of its value as U.S. tariffs on nearly all imported solar panels have impacted the industry in a big way.

But it's not all bad news: Joining Enphase and SolarEdge is a surprising gainer this year: installer Sunrun Inc (NASDAQ:RUN), which has outperformed the market in a year in which investors had low expectations for most U.S. installers. 

A hand traces a bright line on a chart higher.

Image source: Getty Images.

Let's take a closer look at why Sunrun, SolarEdge, and Enphase have outperformed the market and many of their solar peers so far this year, and what investors should consider going forward. 

Here's a look at how these three leading solar stocks have done this year:

RUN Chart

RUN data by YCharts.

Two battling suppliers have both been short-term winners for investors

For Enphase, its big gains over the past couple of years can best be summed up as a surprising turnaround. Rewind the clock a few years back, and it was one of the leading suppliers of a critical component for solar installs, with its microinverters -- which convert the electricity from solar panels from DC to the AC the grid (and most everything in your home) operates on. But by mid-2017, competition from SolarEdge, one of the other names on our list of top performers this year, had taken a substantial amount of Enphase's market share and put it on the brink of collapse

However, Enphase management steadied the ship by improving its expense structure, making investments in its technology that drove costs down (and margins up), and establishing more competitive pricing that helped the company start winning more business. Since that low point, Enphase shares have skyrocketed, gaining over 600%. 

ENPH Chart

ENPH data by YCharts.

A recent deal with SunPower is set to drive sales and profits even higher. In June, Enphase bought that company's microinverter business, and it will become its sole supplier, which is expected to add as much as $70 million in annual sales to the company's top line by late next year -- and at higher gross margins than it currently generates. If the company can maintain its technology edge and keep its costs in line, its future prospects could remain bright. Still, as history has already shown, there are no promises that it won't get disrupted again. 

The performance of SolarEdge so far this year -- really since the beginning of 2017 -- should offer a cautionary tale for Enphase investors. While it joins Enphase on this list of top performers so far this year, a big portion of SolarEdge's gains -- shares are up more than 326% since the start of 2017 -- are due to the success of its power optimizers at taking market share away from Enphase. 

SEDG Chart

SEDG data by YCharts.

That's not to say that this is a "winner take all" situation. The reality is, both SolarEdge and Enphase have strong reasons to co-exist as key suppliers in the burgeoning global solar market. I just wouldn't bet the farm on one over the other -- or ignore the risk of unexpected disruption from somewhere else entirely. 

Backing into first place?

Installer puts solar panels on a roof.

Image source: Getty Images.

Solar installer Sunrun is now the biggest residential solar installer in the U.S., a distinction that loses some of its luster in the face of the cyclical weakness in the U.S. residential market over the past year and the reality that its biggest competitor -- erstwhile SolarCity, now wholly owned by Tesla (NASDAQ:TSLA) -- has been shrinking its residential installation business for the past year-plus.

Nonetheless, the company has taken advantage of the opportunity to aggressively expand, and it aims to grow total megawatts deployed by 15% this year. Furthermore, there are multiple positives that should bode well for Sunrun and other residential installers in the years ahead. First, energy storage is gaining a lot of momentum as prices improve, and Sunrun is demonstrating this by selling its "Brightbox" storage solution to more than 20% of its direct customers in California, its biggest market. 

Furthermore, California's new solar mandate for new homes could be huge for Sunrun and its California-focused peers. Starting after 2020, new homes built in that state are required to include solar panels, which could be worth billions in sales in that state alone. 

Short-term gains -- and losses -- can distract from the long-term opportunity

Operating in one of the most dynamic sectors of the energy industry, solar companies have felt the effects of disruptive technology and government actions like tariffs to the downside and tax incentives to the upside in recent years, which have altered the trajectory of the segment in the near term. This can make it terribly difficult to predict which stocks will be winners or losers over the short term, turning today's hot stocks into tomorrow's big losers -- and vice-versa. 

What's an investor to do? It's a good idea to avoid too much exposure to a single stock, keep an eye on the balance sheet, and track the history of managing expenses for the companies you follow, since sudden policy changes or a disruptive technology can have huge repercussions. The path of investing failure is paved with billions in losses from companies with great ideas and terrible capital management. 

Looking at the long term, the solar industry remains a bright spot for many years of growth, likely underpinned by technology leaders like First Solar and SunPower. Vivent and Sunrun have proven more resilient than I admittedly expected this year, and their prospects could get brighter as energy storage becomes more competitive and the market adapts to tariffs. But I'm not comfortable calling either out as remaining top solar investments over the long term -- at least not yet.