redux-toolkit
redux-toolkit copied to clipboard
Ensures there is no unexpected slash in url before query params
Fixes reduxjs/redux-toolkit#2379
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 |
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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site settings.
@phryneas @markerikson pls take a look if this one makes sense
I'm gonna give it a thorough look in the evening :)
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 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.
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?
Ok, yea, that makes more sense. Thanks
ok @phryneas I think this should do it
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.
I'm happy with the current behaviour, merging this now.