With so much going on in Avengers: Infinity War, it's amazing that the story was able to balance all the characters so well. However, it apparently took some work to get there. The screenwriters of the film admit that the opening sequence of the movie went through a number of different iterations. However, it turns out that the main reason for that was that they didn't know how Thor: Ragnarok was actually going to end when they started writing Infinity War. According to co-writer Christopher McFeely...
We're starting this script in December... let's say January of 2016. There's no Ragnarok script. They're in various stages of development. And so, the first scene of this movie changed a bunch, until we figured out that they were going to end on a trip, off of a destroyed Asgard, we didn't know where Thanos would find Loki.
There's a perception that the Marvel Cinematic Universe is largely set out in advance and that major overall plot points are handed over to filmmakers, with a need for certain films to deal with certain characters or plots in order to make them fit properly into the larger story. Avengers: Infinity War writers Stephen Markus and Christopher McFeely make it clear in their commentary track for the Infinity War Blu-ray that this is not the case. Instead, the pair are hitting a moving target, apparently making changes to the opening of their movie several times as Thor: Ragnarok makes changes to its own story. Clearly, nobody told Taika Waititi where Ragnarok needed to end so that Infinity War would start in the right place.
While the details of how the opening unfolded were apparently quite flexible over the course of the screenwriting process, Stephen Markus says that the basic idea of how the movie would open did remain intact. The movie always opened with Thanos and Loki, but where that happened kept changing.
We did know we wanted Thanos to come to Loki. We had drafts of him in any number of places.
If Thanos always came to Loki then there's a good chance that the end result of that scene was always there as well. It was a fairly shocking way to start the film, but one that successfully set up the emotional story that was to come.
This just goes to show that things are far more fluid in the MCU than many might expect. While Spider-Man: Far From Home can probably count on Peter Parker being alive when his movie starts, it will also need to take into account the events of Infinity War and Avengers 4, that weren't necessarily all known when work began. At the same time, it also means that nobody needs to wait around for all the previous movies to be written to get to work because each writer will still have a lot of freedom in the story they create. So whatever other projects the MCU is planning can still move forward even while the fate of something like Guardians of the Galaxy Vol. 3 is very much up in the air.