Katy Long is a writer, broadcaster and researcher who works on migration and citizenship issues. She is the author of "The Huddled Masses: Immigration and Inequality" and co-editor of "The Oxford Handbook of Refugee and Forced Migration Studies."

The Supreme Court may not be a reliable ally for opponents of the travel ban. (Jon Elswick/Associated Press)

The Supreme Court’s decision last week to allow part of President Trump’s travel ban to take effect means immigration officials will spend their summer sorting strangers from those with genuine U.S. relationships. Travelers from six Muslim-majority nations are now temporarily banned from entering the United States unless they can prove a “bona fide” American connection, pending a final decision by the court in the fall.

Until then, liberal America will hold its breath, hoping that come October, the justices will be convinced to strike down Executive Order 13780. Yet it would be unwise, especially in the long-term, to trust the Supreme Court to hold back a rising tide of nationalist populism. The fate of Chinese migrants in the 1880s — who appealed to U.S. law as a defense against their arbitrary exclusion — should remind us that the courts are not always the allies of those who fight exclusion based on popular prejudice.

In the 1870s, economic insecurity among the white working classes sparked protests against Chinese migrants and gave rise to populist anti-immigrant parties. Newspapers and agitators warned constantly of the “yellow peril,” but it was Chinese migrants who were most frequently imperiled. The largest mass lynching in American history took place in Los Angeles on Oct. 24, 1871, when 17 Chinese immigrants were killed.

Anti-Chinese racism soon gained the force of law. Despite having signed a treaty with China in 1868 recognizing “a person’s inherent and unalienable right to change his home and allegiance,” within 20 years Congress had completed the near-total exclusion of Chinese migrants. The 1875 Page Act — which banned all Chinese suspected of being forced laborers, convicts or prostitutes — was followed, in 1882, by the Chinese Exclusion Act, barring all Chinese immigration for 10 years. The prohibitions against Chinese immigration to the United States were not fully lifted until 1965.

The parallels between these measures and the 2017 travel ban are striking. The initial laws were relatively narrow in scope. An array of exemptions and exclusions created exceptions, allowing — at least initially — some additional Chinese migrants to enter the country.

The 1882 Act officially applied to only Chinese laborers. This allowed merchants, students and government officials, as well as their families, to travel to the United States so long as they could certify their credentials. It also applied only to new immigrants. Those who had already entered the country could remain, and could even return from abroad — if they carried with them the appropriate papers.

To preserve these exemptions, the Chinese appealed to the courts, trying to ensure that only the letter of the law was enforced and not the wider spirit of discrimination in which it had been passed. At first, writs of habeas corpus were used to protect against unlawful detention of those entitled to enter the United States. By the mid-1880s, thousands of writs had brought the entire judicial system in California to a near standstill.

Then in 1884 the test case of Chew Heong v. United States reached the Supreme Court. Chew Heong was a Chinese laborer living in the United States who had left the country before the Exclusion Act had been passed. He returned to San Francisco in 1884, but was refused entry on the grounds that he had no return certificate. In a 7-to-2 ruling, the Supreme Court determined Heong should be readmitted, because he never could have obtained a certificate that had not yet been invented before he left.

The Chinese celebrated, but California’s newspapers eviscerated the ruling. How dare the justices not bend the law to the will of the people? In dissenting from the court’s judgment, Justice Stephen Field prophesied that the ruling would trigger a popular revolt. “I can only express the hope that Congress will, at an early day, speak on the subject in terms which will admit of no doubt as to their meaning.”

Field’s wish was granted. Four years later, Congress passed the Scott Act. Under newly stringent terms, a Chinese migrant who left the United States no longer had the right to return.

Caught in this newly-tightened bureaucratic net, Chinese migrants again flocked to the courts. In 1887, Chae Chan Ping, a Chinese migrant who had lived in San Francisco since 1875, left for a visit to China. Before leaving the United States, he had armed himself with the required return certificate, insuring him — he thought — reentry into the country. But while Ping was en route back to the United States, Congress passed the Scott Act. Upon arrival, he was refused entry.

The grounds for appeal were obvious. How could he have known when he left his home that — under not-yet-passed legislation — he would never be able to return? But this time the courts were indifferent to his plea. The Supreme Court ruled unanimously that under the Scott Act, Chae Chan Ping no longer had any right to enter the country.

The court’s reasons for ruling against Ping should be chilling to opponents of the travel ban. The justices noted Congress had made its intentions clear, and the court could not intervene to change the direction of federal immigration policy. Besides, the court believed that the exclusion of the Chinese was “essential to the peace of the community on the Pacific coast, and possibly to the preservation of our civilization there.” Chae Chan Ping was deported.

Of course, 1882 is not 2017. The Chinese Exclusion Acts were passed by Congress; the travel ban by a presidential executive order. And in targeting Muslims, Trump’s travel ban may violate First Amendment prohibitions against religious discrimination. The Chinese could find no such constitutional refuge with which to protest their exclusion.

Nevertheless, the history of Chinese exclusion offers a cautionary tale. The power of the judiciary to put a stop to popular government policy is limited, especially when it comes to immigration. With the judiciary thus restrained, the political branches can discriminate at will. What starts out as a narrowly defined measure can, if propelled by favorable political and popular winds, slowly swell into near-total prohibition. All this is a reminder that however the Supreme Court rules on the travel ban, this debate will continue.

Because in the end, immigration policy is always about politics — and rarely about justice.