Remove default features when fullstack is enabled and one platform is enabled in the default features (#3925)
* Don't enable default features when only either the server or client is enabled
This commit is contained in:
1 parent
23286ade2b
commit
8c866b783d
14 files changed
+135
-26
No files matched your search
@@ -0,0 +1,11 @@
|
||||
// @ts-check
|
||||
const { test, expect } = require("@playwright/test");
|
||||
|
||||
test("loads with correct features", async ({ page }) => {
|
||||
await page.goto("http://localhost:8002");
|
||||
|
||||
// Expect the page to contain the pending text.
|
||||
const main = page.locator("#main");
|
||||
await expect(main).toContainText('server features: ["server"]');
|
||||
await expect(main).toContainText('client features: ["web"]');
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
.dioxus
|
||||
dist
|
||||
target
|
||||
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "dioxus-playwright-default-features-disabled-test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dioxus = { workspace = true, features = ["fullstack"] }
|
||||
|
||||
[features]
|
||||
# Web is a default feature, but it shouldn't actually be enabled in server builds
|
||||
default = ["web"]
|
||||
server = ["dioxus/server"]
|
||||
web = ["dioxus/web"]
|
||||
@@ -0,0 +1,42 @@
|
||||
// This test asserts that the client feature is disable on the server build by the cli
|
||||
// even if it is set as a default feature
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
let server_features = use_server_future(get_server_features)?.unwrap().unwrap();
|
||||
let mut client_features = use_signal(Vec::new);
|
||||
use_effect(move || {
|
||||
client_features.set(current_platform_features());
|
||||
});
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
"server features: {server_features:?}"
|
||||
}
|
||||
div {
|
||||
"client features: {client_features:?}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn current_platform_features() -> Vec<String> {
|
||||
let mut features = Vec::new();
|
||||
if cfg!(feature = "web") {
|
||||
features.push("web".to_string());
|
||||
}
|
||||
if cfg!(feature = "server") {
|
||||
features.push("server".to_string());
|
||||
}
|
||||
features
|
||||
}
|
||||
|
||||
#[server]
|
||||
async fn get_server_features() -> Result<Vec<String>, ServerFnError> {
|
||||
Ok(current_platform_features())
|
||||
}
|
||||
@@ -166,5 +166,14 @@ module.exports = defineConfig({
|
||||
reuseExistingServer: !process.env.CI,
|
||||
stdout: "pipe",
|
||||
},
|
||||
{
|
||||
cwd: path.join(process.cwd(), "default-features-disabled"),
|
||||
command:
|
||||
'cargo run --package dioxus-cli --release -- serve --force-sequential --addr "127.0.0.1" --port 8002',
|
||||
port: 8002,
|
||||
timeout: 50 * 60 * 1000,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
stdout: "pipe",
|
||||
},
|
||||
],
|
||||
});
|
||||
Reference in new issue
Block a user