From 25959d79cf8ab40764100b9ababbe4ede8ededad Mon Sep 17 00:00:00 2001 From: arctic_hen7 Date: Fri, 8 Oct 2021 07:52:00 +1100 Subject: [PATCH] =?UTF-8?q?fix(templates):=20=F0=9F=90=9B=20inserted=20``=20element=20at=20top=20of=20``?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It now applies to any stylesheets in the `index.html` file, as expected. --- packages/perseus/src/html_shell.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/perseus/src/html_shell.rs b/packages/perseus/src/html_shell.rs index e75293a5e0..7d31f72c07 100644 --- a/packages/perseus/src/html_shell.rs +++ b/packages/perseus/src/html_shell.rs @@ -29,21 +29,29 @@ pub fn prep_html_shell( "", // It's safe to assume that something we just deserialized will serialize again in this case &format!( - "\n\n{}\n\n", + "\n{}\n\n", serde_json::to_string(&render_cfg).unwrap(), load_script, testing_var=if env::var("PERSEUS_TESTING").is_ok() { "window.__PERSEUS_TESTING = true;" } else { "" - }, + } + ), + ); + // Add in the `` element at the very top so that it applies to everything in the HTML shell + // Otherwise any stylesheets loaded before it won't work properly + let prepared_with_base = prepared.replace( + "", + &format!( + "\n", // We add a trailing `/` to the base URL (https://stackoverflow.com/a/26043021) // Note that it's already had any pre-existing ones stripped away - path_prefix=format!("{}/", path_prefix) + path_prefix = format!("{}/", path_prefix) ), ); - prepared + prepared_with_base } /// Interpolates content, metadata, and state into the HTML shell, ready to be sent to the user for initial loads. This should be passed