You are suggesting a possible war between China and the US. There has never been a real shooting war between two nuclear powers. (The Kargil War in 1999 was very limited in scope and, although India and Pakistan both had nuclear capability, it is doubtful either side had many if any deploy-able weapons.) Let's say China attacks US bases on Okinawa or US carriers in the Pacific. Both sides exchange conventional blows. How does this not escalate to a nuclear exchange?
The use of nuclear weapons is a special category (weapons of mass destruction) even within the relatively unconstrained use of force envisioned in high intensity conflict. Generally speaking, in the Post-Cold War era, their use is reserved to those cases where continued existance of the state is threatened. During the Cold War, Soviet and NATO doctrine had these weapons being released to strategic and operational commanders. Though both sides trained for this employment, it, mercifully, never occurred.
Since the existance of the PRC, US, or Japan (as a non-nuclear US ally) is not endangered in this scenario, there has to be another escalating factor that triggers their use. Combat losses, even though severe, are not a justification; their acceptance is part and parcel of the decision to engage in military operations.
The Chinese know this and so does the United States. (Ditto for India and Pakistan in the example you cite.)
Of course, there is always the possibility of a miscalculation, especially when fickle and excitable politicians are involved.