From 51b62dd33a3b499760d3857c2b830b98b99139aa Mon Sep 17 00:00:00 2001 From: Yolo <92775570+HashCookie@users.noreply.github.com> Date: Wed, 9 Aug 2023 01:57:57 +0800 Subject: [PATCH 1/9] fix: readme awesome link (#1320) --- notes/README/ZH_CN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes/README/ZH_CN.md b/notes/README/ZH_CN.md index ca37f7be1..c6bf0f3da 100644 --- a/notes/README/ZH_CN.md +++ b/notes/README/ZH_CN.md @@ -25,7 +25,7 @@ - + Awesome Page From 2a32271fa0f55b8f1238d5b3ac5b186d6725dd3b Mon Sep 17 00:00:00 2001 From: gmorenz Date: Tue, 8 Aug 2023 22:04:15 -0400 Subject: [PATCH 2/9] Set response headers from response, not request, parts (#1328) --- packages/fullstack/src/adapters/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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?; From c6ec2a9a9b37d72978636fee70e7231cdee7e0e5 Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Thu, 10 Aug 2023 01:20:19 +0900 Subject: [PATCH 3/9] docs: add Japanese README (#1329) * Add Japanese README * Add links * minor fix --- README.md | 2 + notes/README/ZH_CN.md | 2 + translations/ja-jp/README.md | 178 +++++++++++++++++++++++++++++++++++ translations/pt-br/README.md | 2 + 4 files changed, 184 insertions(+) create mode 100644 translations/ja-jp/README.md 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 c6bf0f3da..1c4abc667 100644 --- a/notes/README/ZH_CN.md +++ b/notes/README/ZH_CN.md @@ -45,6 +45,8 @@ English | PT-BR + | + 日本語 diff --git a/translations/ja-jp/README.md b/translations/ja-jp/README.md new file mode 100644 index 000000000..342a99cdb --- /dev/null +++ b/translations/ja-jp/README.md @@ -0,0 +1,178 @@ +

+ +

+ +
+ + + 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 | 中文 + | + 日本語 From 92a8669e14c5441a0aa3ac6db9ae437dd03d1522 Mon Sep 17 00:00:00 2001 From: Dan Lock Date: Wed, 9 Aug 2023 17:26:50 +0100 Subject: [PATCH 4/9] Make launch functions pub (#1288) * Make launch functions pub * add docs to web, desktop, and server launch functions --------- Co-authored-by: Evan Almloff --- packages/fullstack/src/launch.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 Date: Wed, 9 Aug 2023 10:26:59 -0700 Subject: [PATCH 5/9] fix variance on components --- packages/core/src/scopes.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index 9470c3d0d..4a21fcb78 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -481,19 +481,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 { From 91500f0349044a1895f8da809f98d2366fd8f0aa Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 9 Aug 2023 10:29:19 -0700 Subject: [PATCH 6/9] add props safety example --- examples/props_safety.rs | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 examples/props_safety.rs diff --git a/examples/props_safety.rs b/examples/props_safety.rs new file mode 100644 index 000000000..7802e75c9 --- /dev/null +++ b/examples/props_safety.rs @@ -0,0 +1,68 @@ +use dioxus::prelude::*; + +fn main() { + dioxus_desktop::launch(app); +} + +fn app(cx: Scope) -> Element { + let count: &RefCell> = cx.use_hook(|| RefCell::new(Vec::new())); + + let element = render! { + div { + "hello world!" + } + }; + + let nested_borrows = cx.use_hook(Vec::new); + nested_borrows.push("hello world!"); + + cx.render(rsx! { + // unsafe_child_component { + // borrowed: count + // } + safe_child_component { + borrowed: element + } + safe_nested_borrows { + borrowed: &**nested_borrows + } + }) +} + +#[derive(Props)] +struct NestedBorrows<'a> { + borrowed: &'a [&'a str], +} + +fn safe_nested_borrows<'a>(cx: Scope<'a, NestedBorrows<'a>>) -> Element<'a> { + render! { + div { "{cx.props.borrowed:?}" } + } +} + +#[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 = borrowed.borrow(); + cx.render(rsx! { + div { "Hello, world!" } + }) +} + +#[derive(Props)] +struct SafeTesting<'a> { + borrowed: Element<'a>, +} + +fn safe_child_component<'a>(cx: Scope<'a, SafeTesting<'a>>) -> Element<'a> { + let SafeTesting { borrowed } = cx.props; + cx.render(rsx! { + div { + borrowed + } + }) +} From f91eeccca784ea2c64c751148d052f513b2c77d2 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 9 Aug 2023 10:49:47 -0700 Subject: [PATCH 7/9] add compile test for unsound case --- packages/core/Cargo.toml | 1 + packages/core/compile_tests/props_safety.rs | 32 +++++++++++++++++++ .../core/compile_tests/props_safety.stderr | 20 ++++++++++++ packages/core/src/properties.rs | 6 ++++ 4 files changed, 59 insertions(+) create mode 100644 packages/core/compile_tests/props_safety.rs create mode 100644 packages/core/compile_tests/props_safety.stderr 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..05f5cbea9 100644 --- a/packages/core/src/properties.rs +++ b/packages/core/src/properties.rs @@ -73,3 +73,9 @@ impl EmptyBuilder { pub fn fc_to_builder<'a, T: Properties + 'a>(_: fn(Scope<'a, T>) -> Element<'a>) -> T::Builder { T::builder() } + +#[test] +fn unsafe_props_fail() { + let t = trybuild::TestCases::new(); + t.compile_fail("compile_tests/props_safety.rs"); +} From 80ac1a99afca6c465e16b37a658169edb387525e Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 9 Aug 2023 14:20:46 -0700 Subject: [PATCH 8/9] fix miri --- examples/props_safety.rs | 68 --------------------------------- packages/core/src/properties.rs | 1 + 2 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 examples/props_safety.rs diff --git a/examples/props_safety.rs b/examples/props_safety.rs deleted file mode 100644 index 7802e75c9..000000000 --- a/examples/props_safety.rs +++ /dev/null @@ -1,68 +0,0 @@ -use dioxus::prelude::*; - -fn main() { - dioxus_desktop::launch(app); -} - -fn app(cx: Scope) -> Element { - let count: &RefCell> = cx.use_hook(|| RefCell::new(Vec::new())); - - let element = render! { - div { - "hello world!" - } - }; - - let nested_borrows = cx.use_hook(Vec::new); - nested_borrows.push("hello world!"); - - cx.render(rsx! { - // unsafe_child_component { - // borrowed: count - // } - safe_child_component { - borrowed: element - } - safe_nested_borrows { - borrowed: &**nested_borrows - } - }) -} - -#[derive(Props)] -struct NestedBorrows<'a> { - borrowed: &'a [&'a str], -} - -fn safe_nested_borrows<'a>(cx: Scope<'a, NestedBorrows<'a>>) -> Element<'a> { - render! { - div { "{cx.props.borrowed:?}" } - } -} - -#[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 = borrowed.borrow(); - cx.render(rsx! { - div { "Hello, world!" } - }) -} - -#[derive(Props)] -struct SafeTesting<'a> { - borrowed: Element<'a>, -} - -fn safe_child_component<'a>(cx: Scope<'a, SafeTesting<'a>>) -> Element<'a> { - let SafeTesting { borrowed } = cx.props; - cx.render(rsx! { - div { - borrowed - } - }) -} diff --git a/packages/core/src/properties.rs b/packages/core/src/properties.rs index 05f5cbea9..f754f8b68 100644 --- a/packages/core/src/properties.rs +++ b/packages/core/src/properties.rs @@ -74,6 +74,7 @@ pub fn fc_to_builder<'a, T: Properties + 'a>(_: fn(Scope<'a, T>) -> Element<'a>) T::builder() } +#[cfg(not(miri))] #[test] fn unsafe_props_fail() { let t = trybuild::TestCases::new(); From 2c79b7fd677da776644003afd4f54e78346edaa0 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Wed, 9 Aug 2023 15:00:57 -0700 Subject: [PATCH 9/9] Update dioxus-core to 0.4.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e6ce4459b..4c420ad3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,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" }