pub async fn get_initial_load_for_path(
        &self,
        path: PathWithoutLocale,
        translator: &Translator,
        template: &Entity<SsrNode>,
        was_incremental: bool,
        req: Request,
    ) -> Result<(PageData, TemplateState), ServerError> {
        let locale = translator.get_locale();
        // Get the latest global state, which we'll share around
        let global_state = self.get_full_global_state(clone_req(&req)).await?;
        // Begin by generating the state for this page
        let page_state = self
            .get_state_for_path_internal(
                path.clone(),
                translator,
                &template.get_path(),
                was_incremental,
                clone_req(&req),
                Some(template),
                Some(global_state.clone()),
                true, // This is an initial load
            )
            .await?;

        let path = PathWithoutLocale(path.strip_suffix('/').unwrap_or(&*path).to_string());
        // Yes, this is created twice; no, we don't care
        // If we're interacting with the stores, this is the path this page/widget will
        // be under
        let path_encoded = format!("{}-{}", locale, urlencoding::encode(&path));

        // The page state generation process will have updated any prerendered fragments
        // of this page, which means they're guaranteed to be up-to-date.
        // Importantly, if any of the dependencies weren't build-safe, or if the page
        // uses request-state (which means, as explained above, we don't
        // actually know what the dependencies are yet, let alone if they're
        // build-safe), this fragment won't exist. Basically, if it exists, we
        // can return it straight away with no extra work. Otherwise, we'll have to do a
        // layer-by-layer render, which can handle non-build-safe dependencies.
        // We call this a 'fragment' because it's not a complete HTML shell etc. (TODO?)
        let prerendered_fragment_res = if template.revalidates() {
            self.mutable_store
                .read(&format!("static/{}.html", &path_encoded))
                .await
        } else {
            self.immutable_store
                .read(&format!("static/{}.html", &path_encoded))
                .await
        };
        // Propagate any errors, but if the asset wasn't found, then record that as
        // `None`
        let prerendered_fragment = match prerendered_fragment_res {
            Ok(fragment) => Some(fragment),
            Err(StoreError::NotFound { .. }) => None,
            Err(err) => return Err(err.into()),
        };

        if let Some(prerendered_fragment) = prerendered_fragment {
            // If there was a prerendered fragment, there will also be a record of the
            // widget states we need to send to the client
            let widget_states = if template.revalidates() {
                self.mutable_store
                    .read(&format!("static/{}.widgets.json", &path_encoded))
                    .await?
            } else {
                self.immutable_store
                    .read(&format!("static/{}.widgets.json", &path_encoded))
                    .await?
            };
            // From the build process, these are infallible
            let widget_states = match serde_json::from_str::<
                HashMap<PathMaybeWithLocale, (String, Value)>,
            >(&widget_states)
            {
                Ok(widget_states) => widget_states,
                Err(err) => return Err(ServerError::InvalidPageState { source: err }),
            };
            Ok((
                PageData {
                    content: prerendered_fragment,
                    head: page_state.head,
                    state: page_state.state.state,
                    widget_states: widget_states
                        .into_iter()
                        // Discard the capsule names and create results (to match with the
                        // possibility of request-time failure)
                        .map(|(k, (_, v))| (k, Ok(v)))
                        .collect(),
                },
                global_state,
            ))
        } else {
            // This will block
            let (final_widget_states, prerendered) = self
                .render_all(
                    HashMap::new(), // This starts empty
                    path,
                    locale.to_string(),
                    page_state.state.clone(),
                    template,
                    global_state.clone(),
                    &req,
                    translator,
                )?
                .await?;
            // Convert the `TemplateState`s into `Value`s
            let final_widget_states = final_widget_states
                .into_iter()
                // We need to turn `TemplateState` into its underlying `Value`
                .map(|(k, res)| (k, res.map(|s| s.state)))
                .collect::<HashMap<_, _>>();

            Ok((
                PageData {
                    content: prerendered,
                    head: page_state.head,
                    state: page_state.state.state,
                    widget_states: final_widget_states,
                },
                global_state,
            ))
        }
    }
Gets the full page data for the given path. This will generate the
state, render the head, and render the content of the page,
resolving all widget dependencies.

This takes a translator to allow the caller to derive it in a way that
respects the likely need to know the translations string as well,
for error page interpolation.

Like `.get_state_for_path()`, this returns the page data and the global
state in a tuple.

# Pitfalls
This currently uses a layer-based dependency resolution algorithm, as a
widget may itself have widgets. However, the widgets a page/widget
uses may be dependent on its state, and therefore we cannot enumerate
the entire dependency tree without knowing all the states involved.
Therefore, we go layer-by-layer. Currently, we wait for each layer
to be fully complete before proceeding to the next one, which leads to
a layer taking as long as the longest state generation within it. This
can lead to poor render times when widgets are highly nested, a
pattern that should be avoided as much as possible.

In future, this will build with maximal parallelism by not waiting for
each layer to be finished building before proceeding to the next
one.
packages/perseus/src/turbine/serve.rs