diff --git a/src/core/component/context.rs b/src/core/component/context.rs
index 9104a9e2..81259720 100644
--- a/src/core/component/context.rs
+++ b/src/core/component/context.rs
@@ -180,6 +180,11 @@ impl Context {
// **< Context RENDER >*************************************************************************
/// Renderiza los recursos del contexto.
+ ///
+ /// Si no se ha definido ningún [`Favicon`], declara un icono vacío para evitar que el navegador
+ /// pida `/favicon.ico` en cada página, una ruta que normalmente no existe y que respondería con
+ /// una página de error completa. Con el icono vacío no hace ninguna petición y muestra su icono
+ /// genérico.
pub fn render_assets(&mut self) -> Markup {
use std::mem::take as mem_take;
@@ -193,6 +198,8 @@ impl Context {
let markup = html! {
@if let Some(fi) = &favicon {
(fi.render(self))
+ } @else {
+ link rel="icon" href="data:,";
}
// Primero los recursos para precarga para iniciar las descargas inmediatamente.
(preloads.render(self))
diff --git a/src/html/assets/favicon.rs b/src/html/assets/favicon.rs
index de5880b0..40b39f6f 100644
--- a/src/html/assets/favicon.rs
+++ b/src/html/assets/favicon.rs
@@ -15,6 +15,10 @@ use crate::{AutoDefault, CowStr};
/// > Los archivos de los iconos deben estar disponibles en el servidor web de la aplicación. Pueden
/// > servirse usando [`serve_static_files!`](crate::serve_static_files).
///
+/// Si una página no declara ningún *favicon*, PageTop declara un icono vacío para que el navegador
+/// no pida `/favicon.ico` en cada página. Por eso un icono servido en `/favicon.ico` no se muestra
+/// si no se declara con este tipo.
+///
/// # Ejemplo
///
/// ```rust,no_run
diff --git a/tests/component_flex.rs b/tests/component_flex.rs
index 79bbf389..1532169f 100644
--- a/tests/component_flex.rs
+++ b/tests/component_flex.rs
@@ -169,7 +169,7 @@ async fn flex_without_display_adds_no_class_of_its_own() {
let html = container.render(&mut cx).await.into_string();
assert!(html.contains(r#"class="own""#));
- assert!(cx.render_assets().into_string().is_empty());
+ assert!(cx.responsive_styles().is_empty());
}
#[pagetop::test]
diff --git a/tests/component_grid.rs b/tests/component_grid.rs
index 48e5b31a..0b0c7640 100644
--- a/tests/component_grid.rs
+++ b/tests/component_grid.rs
@@ -202,7 +202,7 @@ async fn grid_without_display_adds_no_class_of_its_own() {
let html = container.render(&mut cx).await.into_string();
assert!(html.contains(r#"class="own""#));
- assert!(cx.render_assets().into_string().is_empty());
+ assert!(cx.responsive_styles().is_empty());
}
#[pagetop::test]
diff --git a/tests/html_assets_favicon.rs b/tests/html_assets_favicon.rs
new file mode 100644
index 00000000..b3b9f57e
--- /dev/null
+++ b/tests/html_assets_favicon.rs
@@ -0,0 +1,19 @@
+use pagetop::prelude::*;
+
+// Empty icon declared when the page has none.
+const DEFAULT_ICON: &str = r#""#;
+
+#[pagetop::test]
+async fn pages_without_favicon_declare_an_empty_icon() {
+ // Without any declared icon, browsers would request `/favicon.ico` on every page.
+ let assets = Context::default().render_assets().into_string();
+ assert!(assets.contains(DEFAULT_ICON));
+}
+
+#[pagetop::test]
+async fn a_declared_favicon_replaces_the_default_icon() {
+ let mut cx = Context::default().with_assets(Favicon::new().with_icon("/app/icon.png"));
+ let assets = cx.render_assets().into_string();
+ assert!(assets.contains("/app/icon.png"));
+ assert!(!assets.contains(DEFAULT_ICON));
+}
diff --git a/tests/html_props_flex_item.rs b/tests/html_props_flex_item.rs
index e0556fff..32680049 100644
--- a/tests/html_props_flex_item.rs
+++ b/tests/html_props_flex_item.rs
@@ -7,7 +7,7 @@ async fn default_flex_item_adds_nothing() {
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
assert_eq!(html, "");
- assert!(cx.render_assets().into_string().is_empty());
+ assert!(cx.responsive_styles().is_empty());
}
#[pagetop::test]
diff --git a/tests/html_props_grid_item.rs b/tests/html_props_grid_item.rs
index cd99cc84..a13b4d88 100644
--- a/tests/html_props_grid_item.rs
+++ b/tests/html_props_grid_item.rs
@@ -7,7 +7,7 @@ async fn default_grid_item_adds_nothing() {
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
assert_eq!(html, "");
- assert!(cx.render_assets().into_string().is_empty());
+ assert!(cx.responsive_styles().is_empty());
}
#[pagetop::test]
diff --git a/tests/html_props_spacing.rs b/tests/html_props_spacing.rs
index f99b3e5c..af77f1d5 100644
--- a/tests/html_props_spacing.rs
+++ b/tests/html_props_spacing.rs
@@ -7,7 +7,7 @@ async fn default_margin_adds_nothing() {
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
assert_eq!(html, "");
- assert!(cx.render_assets().into_string().is_empty());
+ assert!(cx.responsive_styles().is_empty());
}
#[pagetop::test]
@@ -17,7 +17,7 @@ async fn default_padding_adds_nothing() {
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
assert_eq!(html, "");
- assert!(cx.render_assets().into_string().is_empty());
+ assert!(cx.responsive_styles().is_empty());
}
#[pagetop::test]
@@ -147,7 +147,7 @@ async fn padding_auto_is_ignored() {
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
assert_eq!(html, "");
- assert!(cx.render_assets().into_string().is_empty());
+ assert!(cx.responsive_styles().is_empty());
}
#[pagetop::test]
diff --git a/tests/html_responsives.rs b/tests/html_responsives.rs
index 444b5f78..d331451e 100644
--- a/tests/html_responsives.rs
+++ b/tests/html_responsives.rs
@@ -485,14 +485,15 @@ async fn render_assets_includes_style_tag_with_responsive_styles() {
"flex-basis",
"100%",
));
+ let baseline = Context::default().render_assets().into_string();
assert_eq!(
cx.render_assets().into_string(),
- ""
+ format!("{baseline}")
);
}
#[pagetop::test]
async fn render_assets_omits_style_tag_when_no_responsive_styles() {
let mut cx = Context::default();
- assert_eq!(cx.render_assets().into_string(), "");
+ assert!(!cx.render_assets().into_string().contains("