Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect base_path when pre-rendering static routes #3958

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LeWimbes
Copy link
Contributor

@LeWimbes LeWimbes commented Apr 5, 2025

This pull request fixes #3942 by passing the base_path from the AppBundle to pre_render_static_routes and using it to construct the URL accordingly.

I would like to add a test harness to verify that the base_path is always respected. However, I'd appreciate some guidance on how best to integrate such tests if that's something you'd like to see.

While investigating this issue and testing the example app from #3942 (https://github.com/Gisleburt/dioxus-base-path-issue), I also encountered two additional problems that might be unrelated:

Sometimes content is duplicated or even triplicated.
image

When a non-existent page is requested, the bundle throws an error but then returns a 200 status and renders the homepage without duplicated content.
image

The error:

thread '<unnamed>' panicked at /home/leon/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-router-0.6.3/src/contexts/router.rs:243:17:
route's display implementation must be parsable by FromStr
2025-04-05T13:11:19.269111Z ERROR dioxus_core::any_props: Panic while rendering component `dioxus_router::components::outlet::Outlet<base_path_issue::Route>`: Any { .. }
2025-04-05T13:11:19.269118Z ERROR dioxus_core::scope_arena: Error while rendering component `dioxus_router::components::outlet::Outlet<base_path_issue::Route>`:
Encountered error: CapturedPanic
In scope: ScopeId(5)
Backtrace: disabled backtrace
Context: 

Any feedback or guidance on my fix, the test harness for base_path, and whether you think the other two problems are related or if I should open new issues for them (I couldn't find any open Issues mentioning them) would be much appreciated.

@ealmloff
Copy link
Member

ealmloff commented Apr 7, 2025

The fallback route issue sounds like #3644. I don't think it is related. Content doubling could be caused by a hydration issue caused by #3644

We use playwright to test regressions for some similar issues. You can add the playwright test to this folder. You will need to add a new crate with the base path, and a playwright js test file. The fullstack test might be a good starting point

@jkelleyrtp jkelleyrtp added the cli Related to the dioxus-cli program label Apr 9, 2025
@LeWimbes LeWimbes force-pushed the dx-bundle-base-path-fix branch from 860e792 to a6e7426 Compare April 10, 2025 12:12
@LeWimbes
Copy link
Contributor Author

I've added a Playwright test for serving an app with base_path.

However, I struggled adding a test for the bundling and SSG case. When I run the commented-out command in playwright.config.js manually, everything works as expected and I can visit the site at 127.0.0.1:8080/base-path. But when Playwright executes it, I always encounter the error: "Failed to parse static routes from the server." Do you have any ideas on why that might be happening?

Additionally, is there a way to specify the port? I tried using --port as with serve, but that didn't seem to work; using 8080 might not be ideal.

I've also added test-results to the .gitignore (please let me know if the intent was to publish them) and rebased the changes upon the main branch.

@ealmloff
Copy link
Member

I've added a Playwright test for serving an app with base_path.

However, I struggled adding a test for the bundling and SSG case. When I run the commented-out command in playwright.config.js manually, everything works as expected and I can visit the site at 127.0.0.1:8080/base-path. But when Playwright executes it, I always encounter the error: "Failed to parse static routes from the server." Do you have any ideas on why that might be happening?

You might need to pull in the latest commits from main. 12c6938#diff-62798fdae610a4cce6fb5d11419a6306a2381d67743e0ea2a50c1729470e8e6b fixes the post body the CLI sends to the server for SSG.

Additionally, is there a way to specify the port? I tried using --port as with serve, but that didn't seem to work; using 8080 might not be ideal.

--port should work for ssg. It seems like it is working for me with the existing ssg playwright test command. What error did you get?

@LeWimbes
Copy link
Contributor Author

LeWimbes commented Apr 11, 2025

You might need to pull in the latest commits from main. 12c6938#diff-62798fdae610a4cce6fb5d11419a6306a2381d67743e0ea2a50c1729470e8e6b fixes the post body the CLI sends to the server for SSG.

My branch is already up-to-date with main. I found that it actually works when I comment out the "web" test; therefore, it seems that port collisions are the problem.

--port should work for ssg. It seems like it is working for me with the existing ssg playwright test command. What error did you get?

The --port option appears to only work with serve, not with bundle. Also, the server created by bundle doesn't seem to accept a --port option, right? Since the issue was specifically mentioned bundle, I wanted to create a test for that scenario. I could assign the "web" test a different port to free up port 9999.

I also noticed that running serve in SSG mode with a base_path fails ("Failed to parse static routes from the server.") when the --release flag is not set. So far I haven't been able to find the cause of this behavior in debug mode; any insight would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the dioxus-cli program
Projects
None yet
Development

Successfully merging this pull request may close these issues.

base_path does not work with dx bundle
3 participants