From f91f0d57c39360e56074e0a92e486489702b25d1 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 7 Jun 2023 03:03:18 +0200 Subject: [PATCH] fix rendering of components without a shell Pages where the first component was not "shell" were broken --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/render.rs | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a54d05a..7e23b7c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2010,7 +2010,7 @@ dependencies = [ [[package]] name = "sqlpage" -version = "0.6.7" +version = "0.6.8" dependencies = [ "actix-web", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 8941834b..4bb996e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlpage" -version = "0.6.7" +version = "0.6.8" edition = "2021" description = "A SQL-only web application framework. Takes .sql files and formats the query result using pre-made configurable professional-looking components." keywords = ["web", "sql", "framework"] diff --git a/src/render.rs b/src/render.rs index b27be359..53a325d1 100644 --- a/src/render.rs +++ b/src/render.rs @@ -141,23 +141,29 @@ impl RenderContext { }, _ => log::trace!("The first row is not a shell component, so we will render a shell with default properties"), } + log::debug!("Rendering the shell with properties: {shell_properties}"); shell_renderer.render_start(&mut writer, shell_properties)?; - let current_component_name = initial_component.unwrap_or(DEFAULT_COMPONENT); - log::debug!("Creating the first component in the page: '{current_component_name}'"); - let current_component = Self::create_renderer(current_component_name, Arc::clone(&app_state)) + let current_component = Self::create_renderer(DEFAULT_COMPONENT, Arc::clone(&app_state)) .await - .with_context(|| format!("Unable to open the rendering context because opening the {current_component_name} component failed"))?; + .with_context(|| format!("Unable to open the rendering context because opening the {DEFAULT_COMPONENT} component failed"))?; - Ok(RenderContext { + let mut initial_context = RenderContext { app_state, writer, current_component, shell_renderer, recursion_depth: 0, current_statement: 1, - }) + }; + + if let Some(component) = initial_component { + log::trace!("The page starts with a component without a shell: {component}"); + initial_context.handle_row(&initial_row).await?; + } + + Ok(initial_context) } #[async_recursion(? Send)]