Create a Static Site Generation platform; Deduplicate hot reloading code (#2226)

* create static site generation helpers in the router crate

* work on integrating static site generation into fullstack

* move ssg into a separate crate

* integrate ssg with the launch builder

* simplify ssg example

* fix static_routes for child routes

* move CLI hot reloading websocket code into dioxus-hot-reload

* fix some unused imports

* use the same hot reloading websocket code for fullstack

* fix fullstack hot reloading

* move cli hot reloading logic into the hot reload crate

* ssg example working with dx serve

* add more examples

* fix clippy

* fix formatting

* fix hot reload doctest imports

* fix axum imports

* don't run server doc tests

* Fix hot reload websocket doc examples
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-05-22 07:24:15 -05:00
1 parent 460b70e0f0
commit 245003a5d4
59 files changed
+1507 -791

No files matched your search

+36 -1
View File
@@ -9,11 +9,37 @@ use dioxus_lib::prelude::*;
use crate::{
navigation::NavigationTarget,
prelude::{AnyHistoryProvider, IntoRoutable},
prelude::{AnyHistoryProvider, IntoRoutable, SiteMapSegment},
routable::Routable,
router_cfg::RouterConfig,
};
/// This context is set in the root of the virtual dom if there is a router present.
#[derive(Clone, Copy)]
struct RootRouterContext(Signal<Option<RouterContext>>);
/// Try to get the router that was created closest to the root of the virtual dom. This may be called outside of the router.
///
/// This will return `None` if there is no router present or the router has not been created yet.
pub fn root_router() -> Option<RouterContext> {
if let Some(ctx) = ScopeId::ROOT.consume_context::<RootRouterContext>() {
ctx.0.cloned()
} else {
ScopeId::ROOT.provide_context(RootRouterContext(Signal::new_in_scope(None, ScopeId::ROOT)));
None
}
}
pub(crate) fn provide_router_context(ctx: RouterContext) {
if root_router().is_none() {
ScopeId::ROOT.provide_context(RootRouterContext(Signal::new_in_scope(
Some(ctx),
ScopeId::ROOT,
)));
}
provide_context(ctx);
}
/// An error that can occur when navigating.
#[derive(Debug, Clone)]
pub struct ExternalNavigationFailure(pub String);
@@ -39,6 +65,8 @@ struct RouterContextInner {
failure_external_navigation: fn() -> Element,
any_route_to_string: fn(&dyn Any) -> String,
site_map: &'static [SiteMapSegment],
}
impl RouterContextInner {
@@ -119,6 +147,8 @@ impl RouterContext {
})
.to_string()
},
site_map: R::SITE_MAP,
};
// set the updater
@@ -281,6 +311,11 @@ impl RouterContext {
write_inner.update_subscribers();
}
/// Get the site map of the router.
pub fn site_map(&self) -> &'static [SiteMapSegment] {
self.inner.read().site_map
}
pub(crate) fn render_error(&self) -> Element {
let inner_read = self.inner.write_unchecked();
inner_read