Skip to content

Commit 468b37d

Browse files
authored
Enable ssg renderering (#120)
* patch dioxus * use ssg in the CI workflow * bump dioxus version * bump to rc.1 * fix incremental config path * bump dx version * pass --web instead of --platform web
1 parent 9115486 commit 468b37d

File tree

7 files changed

+83
-52
lines changed

7 files changed

+83
-52
lines changed

.github/workflows/gh-pages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ jobs:
3131
cache-on-failure: "false"
3232
- uses: cargo-bins/cargo-binstall@main
3333
- name: Install CLI
34-
run: cargo binstall dioxus-cli -y --force --version 0.7.0-rc.0
34+
run: cargo binstall dioxus-cli -y --force --version 0.7.0-rc.1
3535
- name: Build
36-
run: cd preview && dx build --platform web --release --base-path "components"
36+
run: cd preview && dx build --web --features fullstack --fullstack --ssg --release --base-path "components"
3737
- name: Copy output
3838
run: cp -r target/dx/preview/release/web/public docs
3939
- name: Add gh pages 404

.github/workflows/playwright.yml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,32 @@ jobs:
4141
shardIndex: [1, 2, 3, 4]
4242
shardTotal: [4]
4343
steps:
44-
# Do our best to cache the toolchain and node install steps
45-
- uses: actions/checkout@v4
46-
- uses: actions/setup-node@v4
47-
with:
48-
node-version: lts/*
49-
- name: Install Rust
50-
uses: dtolnay/[email protected]
51-
with:
52-
targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
53-
- uses: Swatinem/rust-cache@v2
54-
with:
55-
cache-all-crates: "true"
56-
cache-on-failure: "true"
57-
- uses: cargo-bins/cargo-binstall@main
58-
- name: Install CLI
59-
run: cargo binstall dioxus-cli -y --force --version 0.7.0-rc.0
60-
- name: Install dependencies
61-
run: cd ./playwright && npm ci
62-
- name: Install Playwright Browsers
63-
run: cd ./playwright && npx playwright install --with-deps
64-
- name: Run Playwright tests
65-
run: cd ./playwright && npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
66-
- name: Upload blob report to GitHub Actions Artifacts
67-
if: ${{ !cancelled() }}
68-
uses: actions/upload-artifact@v4
69-
with:
70-
name: blob-report-${{ matrix.shardIndex }}
71-
path: blob-report
72-
retention-days: 1
44+
# Do our best to cache the toolchain and node install steps
45+
- uses: actions/checkout@v4
46+
- uses: actions/setup-node@v4
47+
with:
48+
node-version: lts/*
49+
- name: Install Rust
50+
uses: dtolnay/[email protected]
51+
with:
52+
targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
53+
- uses: Swatinem/rust-cache@v2
54+
with:
55+
cache-all-crates: "true"
56+
cache-on-failure: "true"
57+
- uses: cargo-bins/cargo-binstall@main
58+
- name: Install CLI
59+
run: cargo binstall dioxus-cli -y --force --version 0.7.0-rc.1
60+
- name: Install dependencies
61+
run: cd ./playwright && npm ci
62+
- name: Install Playwright Browsers
63+
run: cd ./playwright && npx playwright install --with-deps
64+
- name: Run Playwright tests
65+
run: cd ./playwright && npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
66+
- name: Upload blob report to GitHub Actions Artifacts
67+
if: ${{ !cancelled() }}
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: blob-report-${{ matrix.shardIndex }}
71+
path: blob-report
72+
retention-days: 1

.github/workflows/preview.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Install CLI
4646
run: cargo binstall dioxus-cli -y --force --version 0.7.0-rc.0
4747
- name: Build
48-
run: cd preview && dx build --platform web --release --base-path "components/pr-preview/pr-${{ github.event.pull_request.number }}/"
48+
run: cd preview && dx build --web --release --base-path "components/pr-preview/pr-${{ github.event.pull_request.number }}/"
4949
- name: Copy output
5050
run: cp -r target/dx/preview/release/web/public docs
5151
- name: Deploy 🚀

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ cargo run -p preview --features desktop
7575
or for the web build
7676

7777
```
78-
cargo binstall dioxus-cli -y --force --version 0.7.0-rc.0
79-
dx run -p preview --platform web
78+
cargo binstall dioxus-cli -y --force --version 0.7.0-rc.1
79+
dx run -p preview --web
8080
```
8181

8282
## License

playwright/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default defineConfig({
7878
/* Run your local dev server before starting the tests */
7979
webServer: {
8080
cwd: path.join(process.cwd(), "../preview"),
81-
command: "dx run --platform web",
81+
command: "dx run --web",
8282
port: 8080,
8383
timeout: 50 * 60 * 1000,
8484
reuseExistingServer: !process.env.CI,

preview/src/main.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,28 @@ struct ComponentVariantDemoData {
2828
}
2929

3030
fn main() {
31-
dioxus::launch(App);
31+
dioxus::LaunchBuilder::new()
32+
// Set the server config only if we are building the server target
33+
.with_cfg(server_only! {
34+
ServeConfig::builder()
35+
// Enable incremental rendering
36+
.incremental(
37+
dioxus::server::IncrementalRendererConfig::new()
38+
// Store static files in the public directory where other static assets like wasm are stored
39+
.static_dir(
40+
std::env::current_exe()
41+
.unwrap()
42+
.parent()
43+
.unwrap()
44+
.join("public")
45+
)
46+
// Don't clear the public folder on every build. The public folder has other files including the wasm
47+
// binary and static assets required for the app to run
48+
.clear_cache(false)
49+
)
50+
.enable_out_of_order_streaming()
51+
})
52+
.launch(App);
3253
}
3354

3455
#[component]
@@ -104,6 +125,16 @@ impl Route {
104125
}
105126
}
106127

128+
#[cfg(feature = "fullstack")]
129+
#[server(endpoint = "static_routes", output = server_fn::codec::Json)]
130+
async fn static_routes() -> Result<Vec<String>, ServerFnError> {
131+
// The `Routable` trait has a `static_routes` method that returns all static routes in the enum
132+
Ok(Route::static_routes()
133+
.iter()
134+
.map(ToString::to_string)
135+
.collect())
136+
}
137+
107138
#[component]
108139
fn NavigationLayout() -> Element {
109140
use_effect(move || {
@@ -660,6 +691,8 @@ fn ColapsibleCodeBlock(highlighted: HighlightedCode) -> Element {
660691

661692
#[component]
662693
fn ComponentDemo(iframe: Option<bool>, dark_mode: Option<bool>, name: String) -> Element {
694+
let route = router().current::<Route>();
695+
tracing::info!("route: {route}");
663696
let Some(demo) = components::DEMOS
664697
.iter()
665698
.find(|demo| demo.name == name)

primitives/src/scroll_area.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,23 @@ pub fn ScrollArea(props: ScrollAreaProps) -> Element {
9999
let scroll_type = props.scroll_type;
100100
let always_show = props.always_show_scrollbars;
101101

102-
let overflow_style = use_memo(move || match scroll_type() {
102+
let (overflow_x, overflow_y, scrollbar_width) = match scroll_type() {
103103
ScrollType::Auto => match direction() {
104-
ScrollDirection::Vertical => "overflow-y: auto; overflow-x: hidden;",
105-
ScrollDirection::Horizontal => "overflow-x: auto; overflow-y: hidden;",
106-
ScrollDirection::Both => "overflow: auto;",
104+
ScrollDirection::Vertical => (Some("hidden"), Some("auto"), None),
105+
ScrollDirection::Horizontal => (Some("auto"), Some("hidden"), None),
106+
ScrollDirection::Both => (Some("auto"), Some("auto"), None),
107107
},
108108
ScrollType::Always => match direction() {
109-
ScrollDirection::Vertical => "overflow-y: scroll; overflow-x: hidden;",
110-
ScrollDirection::Horizontal => "overflow-x: scroll; overflow-y: hidden;",
111-
ScrollDirection::Both => "overflow: scroll;",
109+
ScrollDirection::Vertical => (Some("hidden"), Some("scroll"), None),
110+
ScrollDirection::Horizontal => (Some("scroll"), Some("hidden"), None),
111+
ScrollDirection::Both => (Some("scroll"), Some("scroll"), None),
112112
},
113113
ScrollType::Hidden => match direction() {
114-
ScrollDirection::Vertical => {
115-
"overflow-y: scroll; overflow-x: hidden; scrollbar-width: none;"
116-
}
117-
ScrollDirection::Horizontal => {
118-
"overflow-x: scroll; overflow-y: hidden; scrollbar-width: none;"
119-
}
120-
ScrollDirection::Both => "overflow: scroll; scrollbar-width: none;",
114+
ScrollDirection::Vertical => (Some("hidden"), Some("scroll"), Some("none")),
115+
ScrollDirection::Horizontal => (Some("scroll"), Some("hidden"), Some("none")),
116+
ScrollDirection::Both => (Some("scroll"), Some("scroll"), Some("none")),
121117
},
122-
});
118+
};
123119

124120
let visibility_class = use_memo(move || {
125121
if always_show() {
@@ -132,7 +128,9 @@ pub fn ScrollArea(props: ScrollAreaProps) -> Element {
132128
rsx! {
133129
div {
134130
class: "{visibility_class}",
135-
style: "{overflow_style}",
131+
overflow_x,
132+
overflow_y,
133+
"scrollbar-width": scrollbar_width,
136134
"data-scroll-direction": match direction() {
137135
ScrollDirection::Vertical => "vertical",
138136
ScrollDirection::Horizontal => "horizontal",

0 commit comments

Comments
 (0)