vike icon indicating copy to clipboard operation
vike copied to clipboard

`urlParsed` removes trailing slash

Open openscript opened this issue 1 year ago • 7 comments

Description

When the urlOriginal is /en/index.pageContext.json?asd=asd and in the address bar is displayed /en/?asd=asd the urlPathname is /en. When the urlOriginal is /en/?asd=asd the urlPathname is /en/.

This behavior is not influenced by disableUrlNormalization: true.

In my opinion the urlPathname should be /en/ when the urlOriginal is /en/index.pageContext.json?asd=asd.

openscript avatar May 02 '24 05:05 openscript

I would be happy to create a PR for this. Probably this lines need to be changed:

https://github.com/vikejs/vike/blob/6dedbfbda96357dcb1fbc21b6643d099948993b4/vike/node/runtime/renderPage/handlePageContextRequestUrl.ts#L25-L36

Are there unit tests for this? Where would you add a unit test?

openscript avatar May 02 '24 06:05 openscript

I agree and PR welcome :+1:

I also agree that'd be good to add some Vitest test for it and create a file vike/vike/node/runtime/renderPage/removePageContextUrlSuffix.spec.ts. Let's export removePageContextUrlSuffix() and after the PR is merged I'll move removePageContextUrlSuffix() in its own file. (Let's move it to its own file later so it's easier for me to read the diffs you made to removePageContextUrlSuffix.)

brillout avatar May 02 '24 07:05 brillout

Inside removePageContextUrlSuffix() we cannot know if it was originally /en/?asd=asd or /en?asd=asd. Should we read Vikes option trailingSlash and act according to that? If so, should trailingSlash be a param in removePageContextUrlSuffix() or for parseUrl()?

openscript avatar May 02 '24 08:05 openscript

Yes, that's an issue: there is no way to know whether /en/index.pageContext.json is for a /en/ or /en URL. I'm thinking a trick could be to use /en//index.pageContext.json if the URL is /en/?

Inside removePageContextUrlSuffix() we cannot know if it was originally /en/?asd=asd or /en?asd=asd. Should we read Vikes option trailingSlash and act according to that? If so, should trailingSlash be a param in removePageContextUrlSuffix() or for parseUrl()?

That would be a brittle solution as it would fail for /en URLs then.

brillout avatar May 02 '24 08:05 brillout

Ah, actually more natural: /en/index.pageContext.json/. Much clearer I think.

brillout avatar May 02 '24 08:05 brillout

Where would the trailing slash /en/index.pageContext.json/ be added?

openscript avatar May 02 '24 08:05 openscript

See vike/shared/getPageContextRequestUrl.ts

On Thu, May 2, 2024 at 10:45 AM Robin @.***> wrote:

Where would the trailing slash /en/index.pageContext.json/ being added?

— Reply to this email directly, view it on GitHub https://github.com/vikejs/vike/issues/1629#issuecomment-2089921213, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHVQRRO7N33WP4LLZXSEWDZAH4MHAVCNFSM6AAAAABHDBD3OOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBZHEZDCMRRGM . You are receiving this because you commented.Message ID: @.***>

brillout avatar May 02 '24 08:05 brillout

Closing as it doesn't seem fixable, see https://github.com/vikejs/vike/pull/1632#issuecomment-2104462175.

@openscript Let me know whether this is a blocker for you. Otherwise I'll move on and focus on other priorities.

brillout avatar May 10 '24 11:05 brillout

Thank you @brillout. Even though a nice way to handle this, I'm happy that we collaborated.

It's not a blocker as I can handle it case by case in my implementation.

openscript avatar May 11 '24 19:05 openscript