redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Ensures there is no unexpected slash in url before query params

Open ygrishajev opened this issue 2 years ago • 10 comments

Fixes reduxjs/redux-toolkit#2379

ygrishajev avatar Jun 30 '22 06:06 ygrishajev

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 188349864028005261f71b128d45a3178090b7d6:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration

codesandbox-ci[bot] avatar Jun 30 '22 06:06 codesandbox-ci[bot]

Deploy Preview for redux-starter-kit-docs ready!

Name Link
Latest commit 188349864028005261f71b128d45a3178090b7d6
Latest deploy log https://app.netlify.com/sites/redux-starter-kit-docs/deploys/62ff1ac4ac90a70008a50465
Deploy Preview https://deploy-preview-2470--redux-starter-kit-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Jun 30 '22 06:06 netlify[bot]

@phryneas @markerikson pls take a look if this one makes sense

ygrishajev avatar Jun 30 '22 07:06 ygrishajev

I'm gonna give it a thorough look in the evening :)

phryneas avatar Jun 30 '22 07:06 phryneas

I think now you went too far 😅

My point was really just about removing a trailing slash before a ? if the user manually added the trailing slash before.

The other behavior is what it is - and I think also quite "expected". We couldn't change that without a major release even if we wanted - just the small fix for #2379 could count as a "bugfix" release though.

phryneas avatar Jun 30 '22 22:06 phryneas

@phryneas sorry, I think I don't follow. Initial issue I opened is that there is a trailing slash appearing which is not added.

export const api = createApi({
  reducerPath: 'api',
  baseQuery: fetchBaseQuery({ baseUrl: '/api/foo' }),
  endpoints: (builder) => ({
    findAll: builder.query({
      query: (params) => ({ url: '', params }) // `url` is empty, so I expect the request to be sent to `/api/foo?$foo=bar`, not `/api/foo/?$foo=bar`
    })
  })
});

Current implementation is really adding a slash out of the blue. If trailing slashes are untouched it seems to me more explicit, obvious and up to a user how to handle that.

Anyway, if you provide an example to how you think this should work it'd be helpful.

ygrishajev avatar Jul 01 '22 04:07 ygrishajev

Phew... that is really hard to get over through text :sweat_smile: Your previous PR was perfectly fine except where it removed a trailing slash where the user had actively entered the trailing slash themselves.

So,

baseUrl url param result
foo bar foo/bar
foo/ bar foo/bar
foo /bar foo/bar
foo/ /bar foo/bar
foo bar { a: 1 } foo/bar?a=1
foo bar/ { a: 1 } foo/bar/?a=1
foo { a: 1 } foo?a=1
foo/ { a: 1 } foo/?a=1

does that make it a bit more clear?

phryneas avatar Jul 01 '22 07:07 phryneas

Ok, yea, that makes more sense. Thanks

ygrishajev avatar Jul 01 '22 14:07 ygrishajev

ok @phryneas I think this should do it

ygrishajev avatar Jul 01 '22 18:07 ygrishajev

I have a base URL than ends with @.
In my endpoint, I give it a parameter which I imagine would look like: @foo, but the result is rather: @/foo.

Will this PR help me with my issue or should I create a new issue?

CC @phryneas UPDATE: See my comment below.

ibrahim-delice avatar Aug 11 '22 12:08 ibrahim-delice

I'm happy with the current behaviour, merging this now.

phryneas avatar Aug 19 '22 05:08 phryneas