Skip to content

Commit 50050b3

Browse files
Polish Docs (#4112)
* fix(branding): do not scare away new adopters In fact Yew has the reputation of being the most «mature» Rust frontend framework. * fix(docs): correct outdated website docs: camelCase svg elements just work now. * docs: mention nested router RFC * docs: update SSR situation * docs: remove experimental warning and glaze yew-autoprops * docs: promote tracing-web as recommended logging crate * fix: make the svg icon a real square * fix(website): icon not showing * branding: tagline
1 parent 3650fc8 commit 50050b3

45 files changed

Lines changed: 551 additions & 467 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242

4343
Yew is named after a type of evergreen tree, and is pronounced /juː/. [Entry with audio on Cambridge Dictionary](https://dictionary.cambridge.org/dictionary/english/yew).
4444

45-
*Note: Yew is not 1.0 yet. Be prepared to do major refactoring due to breaking API changes.*
46-
4745
## Contributing
4846

4947
Yew is a community-driven effort and we welcome all kinds of contributions, big or small, from developers of all backgrounds. We want the Yew community to be a fun and friendly place, so please review our [Code of Conduct](https://github.com/yewstack/yew/blob/master/CODE_OF_CONDUCT.md) to learn what behavior will not be tolerated.

website/docs/advanced-topics/server-side-rendering.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,8 @@ Example: [wasi_ssr_module](https://github.com/yewstack/yew/tree/master/examples/
261261
If you are using the `wasm32-unknown-unknown` target to build a SSR application, you can use the `not_browser_env` feature flag to disable access of browser-specific APIs inside of Yew. This would be useful on serverless platforms like Cloudflare Worker.
262262
:::
263263

264-
:::caution
264+
:::note
265265

266-
Server-side rendering is currently experimental. If you find a bug, please file
267-
an issue on [GitHub](https://github.com/yewstack/yew/issues/new?assignees=&labels=bug&template=bug_report.md&title=).
266+
We are improving the SSR experience by providing integration with popular frameworks like Axum. Feel free to submit PRs with your favorite frameworks.
268267

269268
:::

website/docs/concepts/function-components/properties.mdx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,33 @@ fn Greetings(
310310
// `name` will use references because of the leading `&` in the definition.
311311
```
312312

313+
Compared to standalone prop structs, `yew-autoprops` has the additional advantage of exposing unused props.
314+
315+
```rust
316+
use yew::prelude::*;
317+
use yew_autoprops::autoprops;
318+
319+
#[autoprops]
320+
#[component]
321+
// highlight-next-line
322+
pub fn Foo(bar0: AttrValue, bar1: AttrValue) -> Html {
323+
// `bar1` will turn into a compiler warning about unused variables
324+
html! {<div>{bar0}</div>}
325+
}
326+
327+
#[derive(PartialEq, Properties, Clone)]
328+
pub struct BarProps {
329+
bar0: AttrValue,
330+
// this property is unused but the compiler cannot detect it
331+
bar1: AttrValue,
332+
}
333+
334+
#[component]
335+
pub fn Bar(props: &BarProps) -> Html {
336+
html! {<div>{&props.bar0}</div>}
337+
}
338+
```
339+
313340
## Evaluation Order
314341

315342
Props are evaluated in the order they're specified, as shown by the following example:
@@ -348,7 +375,3 @@ These include, but are not limited to:
348375
See that crate to learn more.
349376
4. You tell us. Did you run into an edge-case you wish you knew about earlier? Feel free to create an issue
350377
or PR a fix to this documentation.
351-
352-
## yew-autoprops
353-
354-
[yew-autoprops](https://crates.io/crates/yew-autoprops) is an experimental package that allows one to create the Props struct on the fly out of the arguments of your function. Might be useful, if the properties struct is never reused.

website/docs/concepts/html/introduction.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ The `html!` macro allows you to write HTML and SVG code declaratively. It is sim
1313

1414
**Important notes**
1515

16-
1. The `html!` macro accepts any number of root nodes, including zero. An empty
17-
`html! {}` invocation is valid and will not render anything.
18-
2. Literals must always be quoted and wrapped in braces: `html! { <p>{ "Hello, World" }</p> }`
19-
3. The `html!` macro will make all tag names lowercase. To use upper case characters (which are required for some SVG elements) use [dynamic tag names](concepts/html/elements.mdx#dynamic-tag-names): `html! { <@{"myTag"}></@> }`
16+
1. The `html!` macro accepts any number of root nodes. An empty `html! {}` invocation will not render anything.
17+
2. String literals need to be quoted and usually needs to be wrapped in braces: `html! { <p>{ "Hello, World" }</p> }`.
18+
3. Bool types and number types can be used directly: `html!{ <span>{1}</span> <span>{true}</span> }`
2019

2120
:::note
2221
The `html!` macro can reach the default recursion limit of the compiler. If you encounter compilation errors,

website/docs/concepts/router.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,6 @@ because the inner `SettingsRoute` only defines routes without a bare trailing sl
426426
(see [Trailing Slashes](#trailing-slashes)). Unrecognized sub-paths like `/settings/gibberish`
427427
are redirected to the main `NotFound` route at `/404`.
428428

429-
:::caution
430-
431-
Though note that this is still a work in progress so the way we do this is not final
432-
433-
:::
434-
435429
It can be implemented with the following code:
436430

437431
```rust
@@ -502,6 +496,12 @@ pub fn app() -> Html {
502496
}
503497
```
504498

499+
:::caution
500+
501+
If you want more ergonomic nested router support. Please comment under [the first-class nested routing RFC](https://github.com/yewstack/yew/discussions/4111).
502+
503+
:::
504+
505505
### Basename
506506

507507
It's possible to define a basename with `yew-router`.

website/docs/more/debugging.mdx

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,26 @@ Yew automatically logs panics in the browser console.
1010

1111
In JavaScript, `console.log()` is used to log to the browser console. Some options for Yew are listed below.
1212

13-
### [`wasm-logger`](https://crates.io/crates/wasm-logger)
13+
### [`tracing-web`](https://crates.io/crates/tracing-web) (recommended)
1414

15-
`wasm-logger` crate integrates with [`log`](https://crates.io/crates/log) crate to send the log level, source line, and filename to the browser console.
15+
`tracing-web` can be used with [`tracing-subscriber`](https://crates.io/crates/tracing-subscriber) to output messages to the browser console. It works seamlessly on both the client and the server, making it a natural fit for SSR applications where you want a single logging setup across both ends.
1616

1717
```rust ,ignore
18-
use log::info;
18+
use tracing_subscriber::prelude::*;
1919
use wasm_bindgen::JsValue;
2020

2121
fn main() {
22-
wasm_logger::init(wasm_logger::Config::default());
22+
let fmt_layer = tracing_subscriber::fmt::layer()
23+
.with_ansi(false) // only partially supported across browsers
24+
.without_time() // browsers can show timestamps natively in the dev console
25+
.with_writer(tracing_web::MakeWebConsoleWriter::new());
26+
27+
tracing_subscriber::registry()
28+
.with(fmt_layer)
29+
.init();
2330

2431
let object = JsValue::from("world");
25-
info!("Hello {}", object.as_string().unwrap());
32+
tracing::info!("Hello {}", object.as_string().unwrap());
2633
}
2734
```
2835

@@ -41,40 +48,25 @@ fn main() {
4148
}
4249
```
4350

44-
### [`tracing-web`](https://crates.io/crates/tracing-web)
51+
### [`wasm-logger`](https://crates.io/crates/wasm-logger) (unmaintained)
4552

46-
`tracing-web` can be used with [`tracing-subscriber`](https://crates.io/crates/tracing-subscriber) to output messages to the browser console.
53+
`wasm-logger` crate integrates with [`log`](https://crates.io/crates/log) crate to send the log level, source line, and filename to the browser console. Note that this crate is no longer actively maintained. Consider using `tracing-web` instead.
4754

4855
```rust ,ignore
49-
use tracing_subscriber::{
50-
fmt::{
51-
format::{FmtSpan, Pretty},
52-
time::UtcTime,
53-
},
54-
prelude::*,
55-
};
56+
use log::info;
5657
use wasm_bindgen::JsValue;
5758

5859
fn main() {
59-
let fmt_layer = tracing_subscriber::fmt::layer()
60-
.with_ansi(false)
61-
.with_timer(UtcTime::rfc_3339())
62-
.with_writer(tracing_web::MakeConsoleWriter)
63-
.with_span_events(FmtSpan::ACTIVE);
64-
let perf_layer = tracing_web::performance_layer().with_details_from_fields(Pretty::default());
60+
wasm_logger::init(wasm_logger::Config::default());
6561

66-
tracing_subscriber::registry()
67-
.with(fmt_layer)
68-
.with(perf_layer)
69-
.init();
7062
let object = JsValue::from("world");
71-
tracing::info!("Hello {}", object.as_string().unwrap());
63+
info!("Hello {}", object.as_string().unwrap());
7264
}
7365
```
7466

7567
## Debugging component lifecycles
7668

77-
[`tracing`](https://crates.io/crates/tracing) can be used to collect event information related to a component's lifecycle. `tracing` also comes with a feature flag for `log` support, which integrates nicely with `wasm-logger`.
69+
[`tracing`](https://crates.io/crates/tracing) can be used to collect event information related to a component's lifecycle. `tracing` also comes with a feature flag for `log` support, which integrates nicely with `tracing-web`.
7870

7971
[Compile time filters](https://docs.rs/tracing/latest/tracing/level_filters/index.html#compile-time-filters) can be used to adjust verbosity or disable logging, which should result in a smaller Wasm file.
8072

website/docusaurus.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ module.exports = {
1313
favicon: 'img/logo.svg',
1414
organizationName: 'yewstack', // Usually your GitHub org/user name.
1515
projectName: 'yew', // Usually your repo name.
16+
headTags: [
17+
{
18+
tagName: 'link',
19+
attributes: {
20+
rel: 'icon',
21+
href: '/favicon.ico',
22+
sizes: 'any',
23+
},
24+
},
25+
{
26+
tagName: 'link',
27+
attributes: {
28+
rel: 'apple-touch-icon',
29+
href: '/apple-touch-icon.png',
30+
},
31+
},
32+
],
1633
themeConfig: {
1734
colorMode: {
1835
respectPrefersColorScheme: true,

website/i18n/ja/docusaurus-plugin-content-docs/current/concepts/function-components/properties.mdx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,33 @@ fn Greetings(
302302
// `is_loading` は値としてコンポーネントに渡され、`message` と `name` は定義に先行する `&` があるため参照として渡されます。
303303
```
304304

305+
独立したプロパティ構造体と比較して、`yew-autoprops` には未使用のプロパティを検出できるという追加の利点があります。
306+
307+
```rust
308+
use yew::prelude::*;
309+
use yew_autoprops::autoprops;
310+
311+
#[autoprops]
312+
#[component]
313+
// highlight-next-line
314+
pub fn Foo(bar0: AttrValue, bar1: AttrValue) -> Html {
315+
// `bar1` は未使用変数に関するコンパイラ警告になります
316+
html! {<div>{bar0}</div>}
317+
}
318+
319+
#[derive(PartialEq, Properties, Clone)]
320+
pub struct BarProps {
321+
bar0: AttrValue,
322+
// このプロパティは未使用ですが、コンパイラはそれを検出できません
323+
bar1: AttrValue,
324+
}
325+
326+
#[component]
327+
pub fn Bar(props: &BarProps) -> Html {
328+
html! {<div>{&props.bar0}</div>}
329+
}
330+
```
331+
305332
## 評価順序
306333

307334
属性は指定された順序で評価されます。以下の例を参照してください:
@@ -333,7 +360,3 @@ fn main() {
333360
**なぜ悪いのか?** `Vec<T>``String` と同様にクローンのコストが高いです。`IArray<T>` は参照カウントされたスライス (`Rc<[T]>`) または `&'static [T]` であり、非常に安価にクローンできます。<br />
334361
**注意**`IArray`[implicit-clone](https://crates.io/crates/implicit-clone) からインポートできます。詳細はそのパッケージを参照してください。
335362
4. 新しい発見があるかもしれません。早く知っておきたかったエッジケースに遭遇しましたか?問題を作成するか、このドキュメントに修正のPRを提供してください。
336-
337-
## yew-autoprops
338-
339-
[yew-autoprops](https://crates.io/crates/yew-autoprops) は実験的なパッケージで、関数の引数に基づいて動的にProps構造体を作成することを可能にします。プロパティ構造体が再利用されない場合、これは有用かもしれません。

website/i18n/ja/docusaurus-plugin-content-docs/current/concepts/html/introduction.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import TabItem from '@theme/TabItem'
1212

1313
**重要な注意点**
1414

15-
1. `html!` マクロは、0 を含む任意の数のルートノードを受け入れます。空の `html! {}` 呼び出しは有効で、何もレンダリングしません
16-
2. リテラルは常に引用符で囲み、中括弧で囲む必要があります`html! { <p>{ "Hello, World" }</p> }`
17-
3. `html!` マクロはすべてのタグ名を小文字に変換します。大文字の文字(特定の SVG 要素に必要な文字)を使用するには、[動的タグ名](concepts/html/elements.mdx#dynamic-tag-names) を使用してください`html! { <@{"myTag"}></@> }`
15+
1. `html!` マクロは任意の数のルートノードを受け入れます。空の `html! {}` 呼び出しは何もレンダリングしません
16+
2. 文字列リテラルは引用符で囲む必要があり、通常は中括弧で囲む必要があります`html! { <p>{ "Hello, World" }</p> }`
17+
3. Bool 型と数値型は直接使用できます`html!{ <span>{1}</span> <span>{true}</span> }`
1818

1919
:::note
2020
`html!` マクロはコンパイラのデフォルトの再帰制限に達する可能性があります。コンパイル エラーが発生した場合は、クレートのルートに `#![recursion_limit="1024"]` のような属性を追加して問題を解決してください。

website/i18n/ja/docusaurus-plugin-content-docs/current/concepts/router.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,6 @@ import ThemedImage from '@theme/ThemedImage'
391391

392392
ネストされた `SettingsRouter` は、すべての `/settings` で始まる URL を処理します。外側のルーターでは `/settings/` 用に別の `SettingsSlash` バリアントを定義し、`SettingsRoot` にリダイレクトします。これは、内側の `SettingsRoute` が末尾スラッシュのみのルートを定義していないためです([末尾のスラッシュ](#末尾のスラッシュ) を参照)。`/settings/gibberish` のような認識されないサブパスは、メインの `NotFound` ルート `/404` にリダイレクトされます。
393393

394-
:::caution
395-
396-
このインターフェースはまだ開発中であり、このように記述する方法は最終決定されていません。
397-
398-
:::
399-
400394
以下のコードで実装できます:
401395

402396
```rust
@@ -467,6 +461,12 @@ pub fn app() -> Html {
467461
}
468462
```
469463

464+
:::caution
465+
466+
より使いやすいネストされたルーターのサポートをご希望の場合は、[ファーストクラスのネストルーティング RFC](https://github.com/yewstack/yew/discussions/4111) にコメントしてください。
467+
468+
:::
469+
470470
### ベースパス (Basename)
471471

472472
`yew-router` を使用してベースパス (Basename) を定義できます。

0 commit comments

Comments
 (0)