Hotreloading of for/if/body, formatted strings, literals, component props, nested rsx, light CLI rewrite, cli TUI (#2258)
Hotreload the contents of for loops, if chains, component bodies, props, attributes, and any literals discovered in rsx! Add a TUI renderer to the CLI. Improve the CLI build system to be async and parallel. Refactor RSX to allow partial expansion of expressions. Merge autofmt implementations for consistency. Merge the representation of elements and components under the hood. Add a diagnostics system for rsx for improved error messages. Drop interprocess and move to websockets for communication between the CLI and the server. Assign IDs to nodes and attributes in a stable way to be used in non compiler contexts. Add hotreloading to any body of component/for loop/if chain/etc. --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com> Co-authored-by: Liam Mitchell <liamkarlmitchell@gmail.com>
This commit is contained in:
181 files changed
+12755
-10806
No files matched your search
@@ -256,12 +256,6 @@ where
|
||||
.serve_static_assets(cfg.assets_path.clone())
|
||||
.register_server_functions();
|
||||
|
||||
#[cfg(all(feature = "hot-reload", debug_assertions))]
|
||||
{
|
||||
use dioxus_hot_reload::HotReloadRouterExt;
|
||||
server = server.forward_cli_hot_reloading();
|
||||
}
|
||||
|
||||
server.fallback(
|
||||
get(render_handler).with_state(
|
||||
RenderHandleState::new(app)
|
||||
|
||||
@@ -125,15 +125,22 @@ async fn launch_server(
|
||||
build_virtual_dom: impl Fn() -> VirtualDom + Send + Sync + 'static,
|
||||
context_providers: ContextProviders,
|
||||
) {
|
||||
use crate::prelude::RenderHandleState;
|
||||
use clap::Parser;
|
||||
|
||||
let args = dioxus_cli_config::ServeArguments::from_cli()
|
||||
.unwrap_or_else(dioxus_cli_config::ServeArguments::parse);
|
||||
let addr = args
|
||||
.addr
|
||||
.unwrap_or(std::net::IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)));
|
||||
let addr = std::net::SocketAddr::new(addr, args.port);
|
||||
println!("Listening on http://{}", addr);
|
||||
// Get the address the server should run on. If the CLI is running, the CLI proxies fullstack into the main address
|
||||
// and we use the generated address the CLI gives us
|
||||
let cli_args = dioxus_cli_config::RuntimeCLIArguments::from_cli();
|
||||
let address = cli_args
|
||||
.as_ref()
|
||||
.map(|args| args.fullstack_address())
|
||||
.unwrap_or_else(dioxus_cli_config::AddressArguments::parse)
|
||||
.address();
|
||||
|
||||
// Point the user to the CLI address if the CLI is running or the fullstack address if not
|
||||
let serve_address = cli_args
|
||||
.map(|args| args.cli_address())
|
||||
.unwrap_or_else(|| address);
|
||||
|
||||
#[cfg(feature = "axum")]
|
||||
{
|
||||
@@ -141,6 +148,7 @@ async fn launch_server(
|
||||
use crate::prelude::RenderHandleState;
|
||||
|
||||
let router = axum::Router::new().register_server_functions_with_context(context_providers);
|
||||
|
||||
#[cfg(not(any(feature = "desktop", feature = "mobile")))]
|
||||
let router = {
|
||||
use crate::prelude::SSRState;
|
||||
@@ -149,12 +157,6 @@ async fn launch_server(
|
||||
|
||||
let mut router = router.serve_static_assets(cfg.assets_path.clone());
|
||||
|
||||
#[cfg(all(feature = "hot-reload", debug_assertions))]
|
||||
{
|
||||
use dioxus_hot_reload::HotReloadRouterExt;
|
||||
router = router.forward_cli_hot_reloading();
|
||||
}
|
||||
|
||||
router.fallback(
|
||||
axum::routing::get(crate::axum_adapter::render_handler).with_state(
|
||||
RenderHandleState::new_with_virtual_dom_factory(build_virtual_dom)
|
||||
@@ -162,8 +164,10 @@ async fn launch_server(
|
||||
),
|
||||
)
|
||||
};
|
||||
|
||||
let router = router.into_make_service();
|
||||
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
||||
let listener = tokio::net::TcpListener::bind(address).await.unwrap();
|
||||
|
||||
axum::serve(listener, router).await.unwrap();
|
||||
}
|
||||
#[cfg(not(feature = "axum"))]
|
||||
|
||||
@@ -288,7 +288,6 @@ impl SsrRendererPool {
|
||||
stream.render(resolved_chunk);
|
||||
}
|
||||
}
|
||||
tracing::info!("Suspense resolved");
|
||||
|
||||
// After suspense is done, we render the html after the body
|
||||
let mut post_streaming = String::new();
|
||||
@@ -415,16 +414,6 @@ impl FullstackHTMLTemplate {
|
||||
&self,
|
||||
to: &mut R,
|
||||
) -> Result<(), dioxus_ssr::incremental::IncrementalRendererError> {
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload"))]
|
||||
{
|
||||
// In debug mode, we need to add a script to the page that will reload the page if the websocket disconnects to make full recompile hot reloads work
|
||||
let disconnect_js = dioxus_hot_reload::RECONNECT_SCRIPT;
|
||||
|
||||
to.write_str(r#"<script>"#)?;
|
||||
to.write_str(disconnect_js)?;
|
||||
to.write_str(r#"</script>"#)?;
|
||||
}
|
||||
|
||||
let ServeConfig { index, .. } = &self.cfg;
|
||||
|
||||
to.write_str(&index.post_main)?;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![allow(non_snake_case)]
|
||||
//! Configuration for how to serve a Dioxus application
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
@@ -62,7 +62,7 @@ impl ServeConfigBuilder {
|
||||
let assets_path = self.assets_path.unwrap_or(
|
||||
dioxus_cli_config::CURRENT_CONFIG
|
||||
.as_ref()
|
||||
.map(|c| c.dioxus_config.application.out_dir.clone())
|
||||
.map(|c| c.application.out_dir.clone())
|
||||
.unwrap_or("dist".into()),
|
||||
);
|
||||
|
||||
@@ -78,6 +78,7 @@ impl ServeConfigBuilder {
|
||||
.unwrap_or_else(|| load_index_path(index_path));
|
||||
|
||||
let index = load_index_html(index_html, root_id);
|
||||
|
||||
ServeConfig {
|
||||
index,
|
||||
assets_path,
|
||||
@@ -138,7 +139,6 @@ pub(crate) struct IndexHtml {
|
||||
#[derive(Clone)]
|
||||
pub struct ServeConfig {
|
||||
pub(crate) index: IndexHtml,
|
||||
#[allow(dead_code)]
|
||||
pub(crate) assets_path: PathBuf,
|
||||
pub(crate) incremental: Option<dioxus_ssr::incremental::IncrementalRendererConfig>,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user