This is a common problem with late model XJs, including my 2001.
My XJ does it a lot on hot days or when off-roading, especially after a long slow climb. It's so common that I carry a code reader for clearing the various misfire codes.
I have tried many things to cure including the solution below in the TSB below. I have had the best results by wiring in a switch and an adjustable time-delay relay that leaves the aux fan on for several minutes after the engine has been turned off.
I sometimes wonder if a fresh set of injectors would help prevent this problem. It was not a problem when the XJ had low miles.
A few weeks ago, I noticed that a friend's 2000 TJ had metal insulators under each injector, something XJs do not have. His 4.0 never has a hot soak problem.
I have not been successful finding the insulators online.
TSB
1803103 - 4.0L ROUGH ENGINE IDLE AFTER RESTART FOLLOWING A HOT SOAK
Date: 09/05/03 (supercedes 1802702 dated 09/06/02)
Model Year(s): 1999-2004
Description: NOTE: This bulletin applies to vehicles equipped with a 4.0L engine. This bulletin involves the installation of a fuel injector insulator sleeve.
Details: Customers may describe a 20 to 30 second rough idle following the restart of a heat soaked engine. This condition may be most noticeable when the engine is restarted following a prior 10 to 20 minute heat soak in hot ambient conditions of approximately 32 C (90ºF) or higher. This condition may be consistent with short city stop-and-go driving trips and can be aggravated by the use of fuel with a high ethanol content. Depending upon various conditions a MIL may occur due to DTC P0303 - Cylinder #3 Misfire.
This condition may be caused by heat from the exhaust manifold that following engine shut down migrates to the area around injector #3 and causes fuel vapor to form within the injector. This in turn may cause a momentary misfire of cylinder #3 until the fuel vapor is cleared of injector #3. The insulator sleeve lowers the injector #3 temperature to a point below which the fuel will not normally vaporize.
If vehicle exhibits a rough idle, and if a misfire of cylinder #3 is observed following a 10 to 20 minute hot soak, perform the Repair Procedure.
Parts required:
56028371AA Ignition Wire Shield
Repair procedure:
1. Cut insulator sleeve, p/n 56028371AA, to make two (2) insulator sleeves about 25-30 mm (1 in.) in length. See diagram.
2. Install one sleeve around injector #3, with the slit on the upward facing side of the injector. Install the other sleeve with the slit on the downward facing side of the injector.
3. Confirm sleeve is flush to intake manifold surface around injector.
4. Check injector #3 wire and ensure that the injector is rotated to a 2 o'clock position (from driver?s side of vehicle).