Skip to content

Commit

Permalink
Combine redirect function
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Sep 20, 2022
1 parent e47d452 commit 14af42e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
15 changes: 0 additions & 15 deletions packages/next/client/components/redirect-client.ts

This file was deleted.

15 changes: 15 additions & 0 deletions packages/next/client/components/redirect.ts
@@ -1,6 +1,21 @@
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,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/redirect/client-side/page.js
@@ -1,6 +1,6 @@
'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() {
Expand Down

0 comments on commit 14af42e

Please sign in to comment.