HANOI—On a fence-mending visit to Beijing this week, Vietnam’s top Communist official will face a dilemma that has dogged his country’s leaders for much of the past millennium: how to show deference to China without appearing meek back home.

To pull this off, Vietnamese rulers have resorted to all kinds of diplomatic contortions and outright deceptions during a long history of domination by China. In the 18th century, the emperor Nguyen Hue sent a double to the Chinese court. Earlier, the Vietnamese installed two emperors—a boy who dealt with Beijing and a “senior emperor” who took care of other business.

Such tricks confirmed Beijing’s view of Vietnam as cunning and duplicitous. But there’s no getting around Vietnam’s bind: It can’t escape the demands for humility from its much more powerful neighbor any more than it can run away from its own ancient culture, which is shaped by heroic resistance to Chinese bullying.

Today, Hanoi’s dilemma is particularly acute. An economy increasingly dependent on China adds pressure to get along with Beijing. Yet, after China last May dragged a gigantic oil drilling rig into disputed waters, public sentiment is running heavily against the neighbor to the north.

A Pew survey last year showed that 84% of Vietnamese worry that China’s territorial assertiveness could lead to war.