Set it up at home
If the 30-day route covers your nationality, purpose and dates, use it: you need not add an artificial onward stop. For example, an eligible British tourist can fly London–Shanghai–London.
A and B must be different countries or regions. Paris–Shanghai–Paris fails that route test; Paris–Shanghai–Tokyo passes the route test, subject to the other conditions. Compare the places immediately before and after the mainland stop.
Prepare your passport, transport confirmation and accommodation details; request the appropriate entry procedure at border inspection. Submitting an arrival card alone is not transit permission.
If it goes wrong
Download a fix to read it without a connection.