If the batteries were in the trailers, the trailers could charge up while docked or waiting in the yard, to be managed according to the habits of each particular yard.
If the batteries were in the trailers, solar panels could become the roofs of the trailers, and some of the cost of the electricity would be taken directly from the sun. This would be a new type of material that would replace the plate-thin plastic that currently serves as the roof of most semi trailers. A great proportion of charging would come direct from the roof of the trailer, although not always all of it. It might be enough that they don't need to build out connectors out in the yards, and can leave the yards barren (which is easier for driving and cheaper to install), and the trailers could just top-off while docked to unload and load. Whenever the dock was in disuse, trailers could be backed in early for loading or left late after unloading to continue topping off the charge. The routing computers could assist in this planning, using real-time readouts from radio connected data driven batteries.
If all of this was done, they could also use swappable batteries IN ADDITION, for those edge cases where a dock connection didn't work right or there wasn't the expected amount of sunlight or someone had to drive further around a detour or the sales people did really well or they got routed to timbuktoo, and then they'd go over to the battery swap and swap for charged up batteries. These would only be used as a logistical backup measure plus a few by plan just to keep the capability alive and paid for and maximize advantages of the available capability (of battery swap). There's ample belly room in a trailer for all of this.
If batteries were in the trailers, there's no reason they couldn't, completely at their option, also put motors in the trailers.
Ahhhhh, but then there's the end game: there's no reason there'd need to be a cab. The trailer would have turning wheels in front (8 of them), motors at every axle, and drive themselves. You'd only see trailers going back and forth, without any tractors.
Eventually these would right-size for every particular business model according to the cost factors associated with delivery via a computer-driven vehicle. The cost of the human being would be removed, and therefore, smaller size trailers with smaller loads would not have the same fixed cost sitting in the front tractor any more. It has been calculated that loads that are much smaller than a full length trailer would be optimal, except for the driver cost, which is why freight usually wants to be on the longest possible trailers today with human drivers.
Between now and then, tractors that were self driving could be built to pull existing trailers. Tractors that were human driven could be built to pull new battery-fitted trailers. The possibilities are endless.
Freight is a lot more flexible in a lot of ways than passenger cars. I think this will quickly manifest in the way electric cargo and computer-driven cargo will be built. An opening at the back for a dock and the width and height of the roads are the major limits; it's an extremely flexible ordeal besides those restrictions. I think this arena will have a dozen solutions in the next two decades, and in about four decades, optimal truck sizes will have been sorted out and exist pretty much everywhere driving themselves around -- probably about a handful of predominant sizes, with around 3 dozen legacy sizes still using up their depreciation.
Right after that, humans may evolve to virtual computer programs, and may not need bodies any more, so we might not need cargo any more. But, I think that's an edge possibility: more than likely, cargo will still be needed even in that virtual future, to build and maintain those computers, and the infrastructure for all that cargo and material, and space, and everything else. Plus, most of us will want to "go human" on occasion, inhabit a body, enjoy the pleasures of flesh, feel the fresh air, see the trees and hills and rivers and seas, etc. So, cargo will be needed to transport organic fuel, clothing, all the trappings of the human body, as well as any environmental projects we have to keep the planets happy in ways we want.