Skip to content

Conversation

@binarypie
Copy link
Contributor

Normalize the base path when set to / to prevent routing and asset resolution errors in web. This resolves #5045.

Copy link
Member

@ealmloff ealmloff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Could you move this normalization to when DIOXUS_ASSET_ROOT is set instead of when it is read?

Then we don't need to rerun it every time we read the base path. It could also be in the head instead of the env var depending on the platform.

@binarypie
Copy link
Contributor Author

Thanks! Could you move this normalization to when DIOXUS_ASSET_ROOT is set instead of when it is read?

Then we don't need to rerun it every time we read the base path. It could also be in the head instead of the env var depending on the platform.

Sure can!

DIOXUS_ASSET_ROOT (cli arg, dioxus toml, or env var) it will be
normalized when used.
@binarypie
Copy link
Contributor Author

binarypie commented Dec 3, 2025

This approach covers all three ways (cli, toml, env var) the base_path can be set.

In fact it is likely true that this code in request.rs could be removed. However, I was unsure of the ramifications of doing so.

/// Get the normalized base path for the application with `/` trimmed from both ends. If the base path is not set, this will return `.`.
    pub(crate) fn base_path_or_default(&self) -> &str {
        let trimmed_path = self.base_path().unwrap_or_default().trim_matches('/');
        if trimmed_path.is_empty() {
            "."
        } else {
            trimmed_path
        }
    }

Another point to note. Simply modifying where we internally set DIOXUS_ASSET_ROOT with the value from base_path is not enough because it will break when/if someone overrides the environment variable but does not include a cli arg nor a declaration in the toml config.

@binarypie binarypie requested a review from ealmloff December 3, 2025 07:00
@ealmloff
Copy link
Member

ealmloff commented Dec 3, 2025

Another point to note. Simply modifying where we internally set DIOXUS_ASSET_ROOT with the value from base_path is not enough because it will break when/if someone overrides the environment variable but does not include a cli arg nor a declaration in the toml config.

The CLI always either writes DIOXUS_ASSET_ROOT or the meta element. The way this path is communicated to the front end is an implementation detail. We don't support overwriting that environment variable

@binarypie
Copy link
Contributor Author

Another point to note. Simply modifying where we internally set DIOXUS_ASSET_ROOT with the value from base_path is not enough because it will break when/if someone overrides the environment variable but does not include a cli arg nor a declaration in the toml config.

The CLI always either writes DIOXUS_ASSET_ROOT or the meta element. The way this path is communicated to the front end is an implementation detail. We don't support overwriting that environment variable

I apologize for the confusion here. I assumed that the environment variable was accessible from the comments in the code. I'll revert these and make that change.

…OOT as

this environment variable is not meant for public consumption.
Copy link
Member

@ealmloff ealmloff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, thanks!

@ealmloff ealmloff enabled auto-merge (squash) December 4, 2025 19:49
@ealmloff ealmloff disabled auto-merge December 4, 2025 20:18
@ealmloff ealmloff merged commit 3bcb76b into DioxusLabs:main Dec 4, 2025
19 checks passed
@binarypie binarypie deleted the issue-5045 branch December 4, 2025 20:31
@binarypie binarypie restored the issue-5045 branch December 4, 2025 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting base path to "/" will break asset macro path rendering

2 participants