Static prerender fails when route uses query segments
Problem
When a route uses query segments, a static prerender fails with this error message:
thread 'main' panicked at src\bin\prerender.rs:15:4:
called Result::unwrap() on an Err value: IoError(Os { code: 123, kind: InvalidFilename, message: "The filename, directory name, or volume label syntax is incorrect." })
I suspect the problem is that the route has the question mark (?) before the query parameters which the static prerender attempts to include in the Windows filename for the prerendered page for the route with the query segments.
Steps To Reproduce
Steps to reproduce the behavior:
- Set up a static prerender project: https://www.croftsoft.com/library/tutorials/rust-dioxus-project-setup/
- Make one of the routes use query segments: https://dioxuslabs.com/learn/0.4/router/reference/routes#query-segments
Expected behavior
Prerendering succeeds without error
Environment:
- Dioxus version: 0.4 (maybe 0.4.3 too)
- Rust version: 1.75.0
- OS info: Windows
- App platform: web
Questionnaire
- [ ] I'm interested in fixing this myself but don't know where to start
- [ ] I would like to fix and I have a solution
- [ ] I don't have time to fix this right now, but maybe later
- [X] I would like a workaround where I can parse the query parameters myself
You can modify the default url -> file system path mapping in the incremental renderer config here: https://github.com/DioxusLabs/dioxus/blob/53727b344de9af5bcd160fb99703a09ec0da2da4/packages/ssr/src/incremental_cfg.rs#L99-L102
It looks like something like this:
for segment in route.split(&['/', '?'][..]) {
could be used on line 134
I am going to try the suggested workaround.
I was able to successfully test static prerendering with query segments by using the suggested workaround: https://github.com/david-wallace-croft/dioxus-oidc-prototype/blob/main/src/bin/prerender.rs#L24
I we should strip empty query segments and render any query segments before splitting the string here: https://github.com/DioxusLabs/dioxus/blob/53727b344de9af5bcd160fb99703a09ec0da2da4/packages/ssr/src/incremental_cfg.rs#L134C21-L134C48
If the query is not empty, we should either transform the ? into a valid path character (maybe add the prefix __dx__query? or don't cache query segment routes at all