diff --git a/Cargo.toml b/Cargo.toml index 7bb7d1570..5b55f4628 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ version = "0.4.1" # dependencies that are shared across packages [workspace.dependencies] dioxus = { path = "packages/dioxus", version = "0.4.0" } -dioxus-core = { path = "packages/core", version = "0.4.0" } +dioxus-core = { path = "packages/core", version = "0.4.1" } dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" } dioxus-router = { path = "packages/router", version = "0.4.1" } dioxus-router-macro = { path = "packages/router-macro", version = "0.4.1" } diff --git a/README.md b/README.md index 28f27cd23..52e4408d8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ 中文 | PT-BR + | + 日本語 diff --git a/notes/README/ZH_CN.md b/notes/README/ZH_CN.md index ca37f7be1..1c4abc667 100644 --- a/notes/README/ZH_CN.md +++ b/notes/README/ZH_CN.md @@ -25,7 +25,7 @@ - + Awesome Page @@ -45,6 +45,8 @@ English | PT-BR + | + 日本語 diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml index 7c9515fc0..71afe5825 100644 --- a/packages/core/Cargo.toml +++ b/packages/core/Cargo.toml @@ -39,6 +39,7 @@ dioxus = { workspace = true } pretty_assertions = "1.3.0" rand = "0.8.5" dioxus-ssr = { workspace = true } +trybuild = "1.0" [features] default = [] diff --git a/packages/core/compile_tests/props_safety.rs b/packages/core/compile_tests/props_safety.rs new file mode 100644 index 000000000..a9729cec9 --- /dev/null +++ b/packages/core/compile_tests/props_safety.rs @@ -0,0 +1,32 @@ +use dioxus::prelude::*; + +fn main() {} + +fn app(cx: Scope) -> Element { + let count: &RefCell> = cx.use_hook(|| RefCell::new(Vec::new())); + + render! { + unsafe_child_component { + borrowed: count + } + } +} + +#[derive(Props)] +struct Testing<'a> { + borrowed: &'a RefCell>>, +} + +fn unsafe_child_component<'a>(cx: Scope<'a, Testing<'a>>) -> Element<'a> { + let Testing { borrowed } = cx.props; + let borrowed_temporary_data = + cx.use_hook(|| String::from("This data is only valid for the lifetime of the child")); + + borrowed + .borrow_mut() + .push(render! {"{borrowed_temporary_data}"}); + + cx.render(rsx! { + div { "Hello, world!" } + }) +} diff --git a/packages/core/compile_tests/props_safety.stderr b/packages/core/compile_tests/props_safety.stderr new file mode 100644 index 000000000..565d7b6cc --- /dev/null +++ b/packages/core/compile_tests/props_safety.stderr @@ -0,0 +1,20 @@ +error[E0521]: borrowed data escapes outside of function + --> compile_tests/props_safety.rs:8:5 + | +5 | fn app(cx: Scope) -> Element { + | -- + | | + | `cx` is a reference that is only valid in the function body + | has type `&'1 Scoped<'1>` +... +8 | / render! { +9 | | unsafe_child_component { +10 | | borrowed: count +11 | | } +12 | | } + | | ^ + | | | + | |_____`cx` escapes the function body here + | argument requires that `'1` must outlive `'static` + | + = note: this error originates in the macro `render` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/packages/core/src/properties.rs b/packages/core/src/properties.rs index 834b0cabd..f754f8b68 100644 --- a/packages/core/src/properties.rs +++ b/packages/core/src/properties.rs @@ -73,3 +73,10 @@ impl EmptyBuilder { pub fn fc_to_builder<'a, T: Properties + 'a>(_: fn(Scope<'a, T>) -> Element<'a>) -> T::Builder { T::builder() } + +#[cfg(not(miri))] +#[test] +fn unsafe_props_fail() { + let t = trybuild::TestCases::new(); + t.compile_fail("compile_tests/props_safety.rs"); +} diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index 8469781c4..5ada89069 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -417,19 +417,20 @@ impl<'src> ScopeState { /// fn(Scope) -> Element; /// async fn(Scope>) -> Element; /// ``` - pub fn component

( + pub fn component<'child, P>( &'src self, - component: fn(Scope<'src, P>) -> Element<'src>, + component: fn(Scope<'child, P>) -> Element<'child>, props: P, fn_name: &'static str, ) -> DynamicNode<'src> where - P: Properties + 'src, + P: Properties + 'child, + 'src: 'child, { let vcomp = VProps::new(component, P::memoize, props); // cast off the lifetime of the render return - let as_dyn: Box + '_> = Box::new(vcomp); + let as_dyn: Box + '_> = Box::new(vcomp); let extended: Box + 'src> = unsafe { std::mem::transmute(as_dyn) }; DynamicNode::Component(VComponent { diff --git a/packages/fullstack/src/adapters/mod.rs b/packages/fullstack/src/adapters/mod.rs index 9133f8a08..98d190919 100644 --- a/packages/fullstack/src/adapters/mod.rs +++ b/packages/fullstack/src/adapters/mod.rs @@ -112,7 +112,7 @@ impl Service for ServerFnHandler { let mut res = http::Response::builder(); // Set the headers from the server context - let parts = server_context.parts.read().unwrap(); + let parts = server_context.response_parts().unwrap(); *res.headers_mut().expect("empty headers should be valid") = parts.headers.clone(); let serialized = result?; diff --git a/packages/fullstack/src/launch.rs b/packages/fullstack/src/launch.rs index 8d125680b..c982a1c90 100644 --- a/packages/fullstack/src/launch.rs +++ b/packages/fullstack/src/launch.rs @@ -119,21 +119,22 @@ impl + +

+ +
+ + + Crates.io version + + + + Download + + + + docs.rs docs + + + + CI status + + + + + Awesome Page + + + + Discord Link + +
+ +
+

+ Web サイト + | + 例 + | + ガイド + | + 中文 + | + PT-BR +

+
+ +
+ +Dioxus は、Rust でクロスプラットフォームのユーザー・インターフェースを構築するための、移植性が高く、パフォーマンスと人間工学に基づいたフレームワークです。 + +```rust +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || 0); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + }) +} +``` + +Dioxus は、ウェブアプリ、デスクトップアプリ、静的サイト、モバイルアプリ、TUI アプリ、ライブビューアプリなどの配信に使用できます。Dioxus は完全にレンダラーに依存せず、あらゆるレンダラーのプラットフォームとして使用可能です。 + +React を知っているのであれば、Dioxus はすでにご存知でしょう。 + +## ユニークな特徴: + +- 10 行以下のコードでネイティブに動作するデスクトップアプリ(Electron は不要!)。 +- 人間工学に基づいたパワフルな状態管理。 +- 包括的なインラインドキュメント - すべての HTML 要素、リスナー、イベントのホバーとガイド。 +- 驚異的な速さ 🔥 🔥 と極めて高いメモリ効率 +- 高速反復のための統合されたホットリロード +- コルーチンとサスペンスによるファーストクラスの非同期サポート +- などなど![リリース記事全文](https://dioxuslabs.com/blog/introducing-dioxus/)を読む。 + +## 対応プラットフォーム + +
+ + + + + + + + + + + + + + + + + + + + + +
Web +
    +
  • WebAssembly を使って DOM に直接レンダリングする
  • +
  • SSR でプレレンダリングし、クライアントの上で再ハイドレーション
  • +
  • シンプルな "hello world "は約 65kb で、React と同等
  • +
  • 開発サーバーを内蔵し、ホットリロードで迅速なイテレーションを実現
  • +
+
デスクトップ +
    +
  • ウェブビューを使ったレンダリング、あるいは実験的に WGPU や Skia を使ったレンダリング
  • +
  • 設定不要。cargo-run を実行するだけで、アプリをビルド可能
  • +
  • 電子的な IPC を必要としないネイティブシステムアクセスの完全サポート
  • +
  • macOS、Linux、Windows に対応。ポータブルで 3 mb より小さなバイナリ
  • +
+
モバイル +
    +
  • ウェブビューを使ったレンダリング、あるいは実験的に WGPU や Skia を使ったレンダリング
  • +
  • iOS と Android をサポート
  • +
  • React ネイティブよりも大幅にパフォーマンスが高い
  • +
+
ライブビュー +
    +
  • アプリケーション、または単一のコンポーネントを完全にサーバー上でレンダリング
  • +
  • Axum や Warp のような人気のある Rust フレームワークとの統合
  • +
  • 極めて低いレイテンシーと 10,000 以上の同時アプリをサポートする能力
  • +
+
ターミナル +
    +
  • ink.js のように、アプリケーションをターミナルに直接レンダリング
  • +
  • ブラウザでおなじみのフレックスボックスと CSS モデルを採用
  • +
  • テキスト入力、ボタン、フォーカスシステムなどの組み込みウィジェット
  • +
+
+
+ +## なぜ Dioxus? + +アプリを構築するための選択肢は山ほどあるのに、なぜ Dioxus を選ぶのでしょうか? + +まず第一に、Dioxus は開発者の体験を優先しています。これは Dioxus 独自のさまざまな機能に反映されています: + +- メタ言語(RSX)とそれに付随する VSCode 拡張機能のオートフォーマット機能 +- デスクトップとウェブの両方で RSX のインタプリタを使用したホットリロード +- 優れたドキュメントの重視 - 私たちのガイドは完全で、私たちの HTML 要素は文書化されています。 +- 簡素化のための多大な研究 + +Dioxus は非常に拡張性の高いプラットフォームでもあります。 + +- 非常にシンプルに最適化されたスタックマシンを実装することで、新しいレンダラーを簡単に構築できます。 +- コンポーネントやカスタム・エレメントもビルドして共有できます + +Dioxus は素晴らしいが、なぜ私には使えないのか? + +- まだ完全に成熟していません。API はまだ移行中で、いろいろなものが壊れるかもしれません(私たちはそれを避けようとしていますが)。 +- no-std 環境で動作させる必要がある。 +- UI を構築する React-hooks モデルが好きではない場合 + +## コントリビュート + +- 私たちの [issue tracker](https://github.com/dioxuslabs/dioxus/issues) で問題を報告してください。 +- ディスコードに参加して質問してください! + + + + + +## ライセンス + +このプロジェクトのライセンスは [MIT ライセンス] です。 + +[MIT ライセンス]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT + +あなたが明示的に別段の定めをしない限り、あなたによって Dioxus に含めるために意図的に提出されたコントリビュートは、 +いかなる追加条件もなく、MIT としてライセンスされるものとします。 diff --git a/translations/pt-br/README.md b/translations/pt-br/README.md index a50727662..2e4376bfb 100644 --- a/translations/pt-br/README.md +++ b/translations/pt-br/README.md @@ -43,6 +43,8 @@ Guia | 中文 + | + 日本語