vike icon indicating copy to clipboard operation
vike copied to clipboard

missing trailing slash in page context url

Open openscript opened this issue 1 year ago • 1 comments

fixes #1629

openscript avatar May 02 '24 12:05 openscript

I'm not sure how we can proceed with /en/index.pageContext.json/. Requests fetching page contexts fail.

openscript avatar May 02 '24 12:05 openscript

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: @.***>

brillout avatar May 02 '24 16:05 brillout

So far:

  • /en/index.pageContext.json?trailingSlash conflicts with query params a user might set
  • /en/index.pageContext.json/ breaks webserver routing
  • /en//index.pageContext.json write 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 avatar May 04 '24 08:05 openscript

@openscript Makes sense :+1:

brillout avatar May 04 '24 08:05 brillout

Where would be a good place to update the url* contexts after the pageContext was fetched?

openscript avatar May 06 '24 13:05 openscript

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.

brillout avatar May 06 '24 13:05 brillout

How about this then:

  • /en => /en/index.pageContext.json
  • /en/ => /en/index.slash.pageContext.json

brillout avatar May 06 '24 14:05 brillout

We can then use pageContext._urlHasTrailingSlash on the server-side only (no need to add it to passToClient).

brillout avatar May 06 '24 14:05 brillout

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.

openscript avatar May 06 '24 14:05 openscript

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.

brillout avatar May 10 '24 11:05 brillout