Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
cbfb8cbc
Unverified
Commit
cbfb8cbc
authored
Aug 06, 2020
by
Jan Potoms
Committed by
GitHub
Aug 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove querystring from the client (#15378)
parent
882288b5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
10 deletions
+54
-10
index.js
packages/next/client/index.js
+7
-5
page-loader.js
packages/next/client/page-loader.js
+1
-1
router.ts
packages/next/next-server/lib/router/router.ts
+1
-1
format-url.ts
packages/next/next-server/lib/router/utils/format-url.ts
+3
-3
querystring.ts
packages/next/next-server/lib/router/utils/querystring.ts
+42
-0
No files found.
packages/next/client/index.js
View file @
cbfb8cbc
/* global location */
/* global location */
import
{
createRouter
,
makePublicRouterInstance
}
from
'next/router'
import
{
createRouter
,
makePublicRouterInstance
}
from
'next/router'
import
{
parse
as
parseQs
,
stringify
as
stringifyQs
}
from
'
querystring'
import
*
as
querystring
from
'../next-server/lib/router/utils/
querystring'
import
React
from
'react'
import
React
from
'react'
import
ReactDOM
from
'react-dom'
import
ReactDOM
from
'react-dom'
import
{
HeadManagerContext
}
from
'../next-server/lib/head-manager-context'
import
{
HeadManagerContext
}
from
'../next-server/lib/head-manager-context'
...
@@ -99,10 +99,12 @@ class Container extends React.Component {
...
@@ -99,10 +99,12 @@ class Container extends React.Component {
router
.
replace
(
router
.
replace
(
router
.
pathname
+
router
.
pathname
+
'?'
+
'?'
+
stringifyQs
({
String
(
...
router
.
query
,
querystring
.
assign
(
...
parseQs
(
location
.
search
.
substr
(
1
)),
querystring
.
urlQueryToSearchParams
(
router
.
query
),
}),
new
URLSearchParams
(
location
.
search
)
)
),
asPath
,
asPath
,
{
{
// WARNING: `_h` is an internal option for handing Next.js
// WARNING: `_h` is an internal option for handing Next.js
...
...
packages/next/client/page-loader.js
View file @
cbfb8cbc
...
@@ -2,7 +2,7 @@ import mitt from '../next-server/lib/mitt'
...
@@ -2,7 +2,7 @@ import mitt from '../next-server/lib/mitt'
import
{
isDynamicRoute
}
from
'./../next-server/lib/router/utils/is-dynamic'
import
{
isDynamicRoute
}
from
'./../next-server/lib/router/utils/is-dynamic'
import
{
getRouteMatcher
}
from
'./../next-server/lib/router/utils/route-matcher'
import
{
getRouteMatcher
}
from
'./../next-server/lib/router/utils/route-matcher'
import
{
getRouteRegex
}
from
'./../next-server/lib/router/utils/route-regex'
import
{
getRouteRegex
}
from
'./../next-server/lib/router/utils/route-regex'
import
{
searchParamsToUrlQuery
}
from
'./../next-server/lib/router/utils/
search-params-to-url-query
'
import
{
searchParamsToUrlQuery
}
from
'./../next-server/lib/router/utils/
querystring
'
import
{
parseRelativeUrl
}
from
'./../next-server/lib/router/utils/parse-relative-url'
import
{
parseRelativeUrl
}
from
'./../next-server/lib/router/utils/parse-relative-url'
import
escapePathDelimiters
from
'../next-server/lib/router/utils/escape-path-delimiters'
import
escapePathDelimiters
from
'../next-server/lib/router/utils/escape-path-delimiters'
import
getAssetPathFromRoute
from
'./../next-server/lib/router/utils/get-asset-path-from-route'
import
getAssetPathFromRoute
from
'./../next-server/lib/router/utils/get-asset-path-from-route'
...
...
packages/next/next-server/lib/router/router.ts
View file @
cbfb8cbc
...
@@ -16,7 +16,7 @@ import {
...
@@ -16,7 +16,7 @@ import {
import
{
isDynamicRoute
}
from
'./utils/is-dynamic'
import
{
isDynamicRoute
}
from
'./utils/is-dynamic'
import
{
getRouteMatcher
}
from
'./utils/route-matcher'
import
{
getRouteMatcher
}
from
'./utils/route-matcher'
import
{
getRouteRegex
}
from
'./utils/route-regex'
import
{
getRouteRegex
}
from
'./utils/route-regex'
import
{
searchParamsToUrlQuery
}
from
'./utils/
search-params-to-url-query
'
import
{
searchParamsToUrlQuery
}
from
'./utils/
querystring
'
import
{
parseRelativeUrl
}
from
'./utils/parse-relative-url'
import
{
parseRelativeUrl
}
from
'./utils/parse-relative-url'
import
{
import
{
removePathTrailingSlash
,
removePathTrailingSlash
,
...
...
packages/next/next-server/lib/router/utils/format-url.ts
View file @
cbfb8cbc
...
@@ -21,7 +21,8 @@
...
@@ -21,7 +21,8 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// USE OR OTHER DEALINGS IN THE SOFTWARE.
import
{
UrlObject
}
from
'url'
import
{
UrlObject
}
from
'url'
import
{
encode
as
encodeQuerystring
}
from
'querystring'
import
{
ParsedUrlQuery
}
from
'querystring'
import
*
as
querystring
from
'./querystring'
const
slashedProtocols
=
/https
?
|ftp|gopher|file/
const
slashedProtocols
=
/https
?
|ftp|gopher|file/
...
@@ -45,8 +46,7 @@ export function formatUrl(urlObj: UrlObject) {
...
@@ -45,8 +46,7 @@ export function formatUrl(urlObj: UrlObject) {
}
}
if
(
query
&&
typeof
query
===
'object'
)
{
if
(
query
&&
typeof
query
===
'object'
)
{
// query = '' + new URLSearchParams(query);
query
=
String
(
querystring
.
urlQueryToSearchParams
(
query
as
ParsedUrlQuery
))
query
=
encodeQuerystring
(
query
)
}
}
let
search
=
urlObj
.
search
||
(
query
&&
`?
${
query
}
`
)
||
''
let
search
=
urlObj
.
search
||
(
query
&&
`?
${
query
}
`
)
||
''
...
...
packages/next/next-server/lib/router/utils/
search-params-to-url-query
.ts
→
packages/next/next-server/lib/router/utils/
querystring
.ts
View file @
cbfb8cbc
...
@@ -15,3 +15,28 @@ export function searchParamsToUrlQuery(
...
@@ -15,3 +15,28 @@ export function searchParamsToUrlQuery(
})
})
return
query
return
query
}
}
export
function
urlQueryToSearchParams
(
urlQuery
:
ParsedUrlQuery
):
URLSearchParams
{
const
result
=
new
URLSearchParams
()
Object
.
entries
(
urlQuery
).
forEach
(([
key
,
value
])
=>
{
if
(
Array
.
isArray
(
value
))
{
value
.
forEach
((
item
)
=>
result
.
append
(
key
,
item
))
}
else
{
result
.
set
(
key
,
value
)
}
})
return
result
}
export
function
assign
(
target
:
URLSearchParams
,
...
searchParamsList
:
URLSearchParams
[]
):
URLSearchParams
{
searchParamsList
.
forEach
((
searchParams
)
=>
{
Array
.
from
(
searchParams
.
keys
()).
forEach
((
key
)
=>
target
.
delete
(
key
))
searchParams
.
forEach
((
value
,
key
)
=>
target
.
append
(
key
,
value
))
})
return
target
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment