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
499ce6db
Unverified
Commit
499ce6db
authored
Sep 20, 2022
by
Tim Neutkens
Committed by
GitHub
Sep 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Combine redirect function in new router (#40717)
parent
c90e5f05
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
25 deletions
+25
-25
hooks-server-context.ts
packages/next/client/components/hooks-server-context.ts
+9
-9
redirect-client.ts
packages/next/client/components/redirect-client.ts
+0
-15
redirect.ts
packages/next/client/components/redirect.ts
+15
-0
page.js
test/e2e/app-dir/app/app/redirect/client-side/page.js
+1
-1
No files found.
packages/next/client/components/hooks-server-context.ts
View file @
499ce6db
...
...
@@ -11,22 +11,22 @@ export class DynamicServerError extends Error {
// https://github.com/facebook/react/blob/dd2d6522754f52c70d02c51db25eb7cbd5d1c8eb/packages/react/src/ReactServerContext.js#L101
const
createContext
=
<
T
>
(
name
:
string
,
defaultValue
:
T
|
null
=
null
)
=>
{
// @ts-expect-error __NEXT_DEV_SERVER_CONTEXT__ is a global
if
(
!
global
.
__NEXT_
DEV_
SERVER_CONTEXT__
)
{
// @ts-expect-error __NEXT_
DEV_
SERVER_CONTEXT__ is a global
global
.
__NEXT_
DEV_
SERVER_CONTEXT__
=
{}
if
(
!
global
.
__NEXT_SERVER_CONTEXT__
)
{
// @ts-expect-error __NEXT_SERVER_CONTEXT__ is a global
global
.
__NEXT_SERVER_CONTEXT__
=
{}
}
// @ts-expect-error __NEXT_
DEV_
SERVER_CONTEXT__ is a global
if
(
!
global
.
__NEXT_
DEV_
SERVER_CONTEXT__
[
name
])
{
// @ts-expect-error __NEXT_
DEV_
SERVER_CONTEXT__ is a global
global
.
__NEXT_
DEV_
SERVER_CONTEXT__
[
name
]
=
createServerContext
(
// @ts-expect-error __NEXT_SERVER_CONTEXT__ is a global
if
(
!
global
.
__NEXT_SERVER_CONTEXT__
[
name
])
{
// @ts-expect-error __NEXT_SERVER_CONTEXT__ is a global
global
.
__NEXT_SERVER_CONTEXT__
[
name
]
=
createServerContext
(
name
,
defaultValue
)
}
// @ts-expect-error __NEXT_
DEV_
SERVER_CONTEXT__ is a global
return
global
.
__NEXT_
DEV_
SERVER_CONTEXT__
[
name
]
// @ts-expect-error __NEXT_SERVER_CONTEXT__ is a global
return
global
.
__NEXT_SERVER_CONTEXT__
[
name
]
}
export
const
CONTEXT_NAMES
=
{
...
...
packages/next/client/components/redirect-client.ts
deleted
100644 → 0
View file @
c90e5f05
import
React
,
{
experimental_use
as
use
}
from
'react'
import
{
AppRouterContext
}
from
'../../shared/lib/app-router-context'
import
{
createInfinitePromise
}
from
'./infinite-promise'
export
function
redirect
(
url
:
string
)
{
const
router
=
use
(
AppRouterContext
)
setTimeout
(()
=>
{
// @ts-ignore startTransition exists
React
.
startTransition
(()
=>
{
router
.
replace
(
url
,
{})
})
})
// setTimeout is used to start a new transition during render, this is an intentional hack around React.
use
(
createInfinitePromise
())
}
packages/next/client/components/redirect.ts
View file @
499ce6db
import
React
,
{
experimental_use
as
use
}
from
'react'
import
{
AppRouterContext
}
from
'../../shared/lib/app-router-context'
import
{
createInfinitePromise
}
from
'./infinite-promise'
export
const
REDIRECT_ERROR_CODE
=
'NEXT_REDIRECT'
export
function
redirect
(
url
:
string
)
{
if
(
process
.
browser
)
{
const
router
=
use
(
AppRouterContext
)
setTimeout
(()
=>
{
// @ts-ignore startTransition exists
React
.
startTransition
(()
=>
{
router
.
replace
(
url
,
{})
})
})
// setTimeout is used to start a new transition during render, this is an intentional hack around React.
use
(
createInfinitePromise
())
}
// eslint-disable-next-line no-throw-literal
throw
{
url
,
...
...
test/e2e/app-dir/app/app/redirect/client-side/page.js
View file @
499ce6db
'client'
import
{
redirect
}
from
'next/dist/client/components/redirect
-client
'
import
{
redirect
}
from
'next/dist/client/components/redirect'
import
React
from
'react'
export
default
function
Page
()
{
...
...
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