missing trailing slash in page context url
fixes #1629
I'm not sure how we can proceed with /en/index.pageContext.json/. Requests fetching page contexts fail.
What's the issue? Can you rebase on top of git fetch; git rebase -i origin/main?
On Thu, May 2, 2024 at 2:55 PM Robin @.***> wrote:
I'm not sure how we can proceed with /en/index.pageContext.json/. Requests fetching page contexts fail.
— Reply to this email directly, view it on GitHub https://github.com/vikejs/vike/pull/1632#issuecomment-2090434129, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHVQRQNMFIEK57N6JN2DG3ZAIZTJAVCNFSM6AAAAABHDU5A3GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJQGQZTIMJSHE . You are receiving this because you are subscribed to this thread.Message ID: @.***>
So far:
-
/en/index.pageContext.json?trailingSlashconflicts with query params a user might set -
/en/index.pageContext.json/breaks webserver routing -
/en//index.pageContext.jsonwrite to file paths with double slash error
An alternative would be to add a property pageContext._urlHasTrailingSlash that is included in pageContext.json (i.e. in the default passToClient values see PASS_TO_CLIENT). That would be the cleanest I guess but maybe a little bit more cumbersome to implement.
I will follow that lead now.
@openscript Makes sense :+1:
Where would be a good place to update the url* contexts after the pageContext was fetched?
Actually, what we need is the other way around: we need the client to tell the server that the URL has a trailing slash. So I'm not sure pageContext._urlHasTrailingSlash would be of any help here.
How about this then:
-
/en=>/en/index.pageContext.json -
/en/=>/en/index.slash.pageContext.json
We can then use pageContext._urlHasTrailingSlash on the server-side only (no need to add it to passToClient).
Is my thinking about the solution wrong? pageContext._urlHasTrailingSlash would be saved in the pageContext.json file. When the client fetches, it reads pageContext._urlHasTrailingSlash from the fetched pageContext.json, then it adjusts the urlOriginal etc.
Maybe it's better if you take over this issue. I feel a bit lost with it.
The client-side is the source of truth. So the bottom line here is that the information needs to be communicated from the client to the server.
I thought more about it and I'm afraid there doesn't seem to a solution. The issue is that pre-rendering requires the pageContext.json file to be written at a unique path and, thus, served at a unique URL. So there isn't a way to determine whether there is a trailing a slash. I went a head and closed, but let me know if you know a framework that supports pre-rendering and trailing slashes and that doesn't have that issue, maybe I missed a solution.