diff --git a/crates/tuono/Cargo.toml b/crates/tuono/Cargo.toml index bdb5a19b..5bf5bd75 100644 --- a/crates/tuono/Cargo.toml +++ b/crates/tuono/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tuono" -version = "0.11.1" +version = "0.11.2" edition = "2021" authors = ["V. Ageno "] description = "The react/rust fullstack framework" diff --git a/crates/tuono_lib/Cargo.toml b/crates/tuono_lib/Cargo.toml index ac8c4778..0cc644b5 100644 --- a/crates/tuono_lib/Cargo.toml +++ b/crates/tuono_lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tuono_lib" -version = "0.11.1" +version = "0.11.2" edition = "2021" authors = ["V. Ageno "] description = "The react/rust fullstack framework" @@ -33,7 +33,7 @@ either = "1.13.0" tower-http = {version = "0.6.0", features = ["fs"]} colored = "2.1.0" -tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.11.1"} +tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.11.2"} # Match the same version used by axum tokio-tungstenite = "0.24.0" futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] } diff --git a/crates/tuono_lib_macros/Cargo.toml b/crates/tuono_lib_macros/Cargo.toml index 17df5ecf..20c5f126 100644 --- a/crates/tuono_lib_macros/Cargo.toml +++ b/crates/tuono_lib_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tuono_lib_macros" -version = "0.11.1" +version = "0.11.2" edition = "2021" description = "The react/rust fullstack framework" keywords = [ "react", "typescript", "fullstack", "web", "ssr"] diff --git a/packages/fs-router-vite-plugin/package.json b/packages/fs-router-vite-plugin/package.json index b71c1c78..25709a01 100644 --- a/packages/fs-router-vite-plugin/package.json +++ b/packages/fs-router-vite-plugin/package.json @@ -1,6 +1,6 @@ { "name": "tuono-fs-router-vite-plugin", - "version": "0.11.1", + "version": "0.11.2", "description": "Plugin for the tuono's file system router. Tuono is the react/rust fullstack framework", "scripts": { "dev": "vite build --watch", diff --git a/packages/lazy-fn-vite-plugin/package.json b/packages/lazy-fn-vite-plugin/package.json index 2545f0f5..f59a48cb 100644 --- a/packages/lazy-fn-vite-plugin/package.json +++ b/packages/lazy-fn-vite-plugin/package.json @@ -1,6 +1,6 @@ { "name": "tuono-lazy-fn-vite-plugin", - "version": "0.11.1", + "version": "0.11.2", "description": "Plugin for the tuono's lazy fn. Tuono is the react/rust fullstack framework", "scripts": { "dev": "vite build --watch", diff --git a/packages/router/package.json b/packages/router/package.json index 056d65c0..01eccb68 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -1,6 +1,6 @@ { "name": "tuono-router", - "version": "0.11.1", + "version": "0.11.2", "description": "React routing component for the framework tuono. Tuono is the react/rust fullstack framework", "scripts": { "dev": "vite build --watch", diff --git a/packages/router/src/dynamic.tsx b/packages/router/src/dynamic.tsx index ad32d94f..7ac598f6 100644 --- a/packages/router/src/dynamic.tsx +++ b/packages/router/src/dynamic.tsx @@ -1,4 +1,5 @@ import * as React from 'react' +import type { ReactElement, ComponentType } from 'react' import type { RouteComponent } from './types' type ImportFn = () => Promise<{ default: React.ComponentType }> @@ -40,7 +41,18 @@ export const dynamic = (importFn: ImportFn): JSX.Element => { } export const lazyLoadComponent = (factory: ImportFn): RouteComponent => { - const Component = React.lazy(factory) as unknown as RouteComponent - Component.preload = factory + let LoadedComponent: ComponentType | undefined + const LazyComponent = React.lazy(factory) as unknown as RouteComponent + + const loadComponent = (): Promise => + factory().then((module) => { + LoadedComponent = module.default + }) + + const Component = (props: any): ReactElement => + React.createElement(LoadedComponent || LazyComponent, props) + + Component.preload = loadComponent + return Component } diff --git a/packages/tuono/package.json b/packages/tuono/package.json index 85f22186..4a0459fc 100644 --- a/packages/tuono/package.json +++ b/packages/tuono/package.json @@ -1,6 +1,6 @@ { "name": "tuono", - "version": "0.11.1", + "version": "0.11.2", "description": "The react/rust fullstack framework", "scripts": { "dev": "vite build --watch",