Skip to content

Commit

Permalink
Revert "chore(location): Accept URL-like object (#10467)"
Browse files Browse the repository at this point in the history
This reverts commit 48ed453.
  • Loading branch information
dac09 committed Apr 18, 2024
1 parent 852e457 commit eb2929f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 2 additions & 6 deletions packages/router/src/location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import { createNamedContext } from './createNamedContext'
import { gHistory } from './history'
import type { TrailingSlashesTypes } from './util'

export interface LocationContextType {
pathname: string
search?: string
hash?: string
}
export interface LocationContextType extends URL {}

const LocationContext = createNamedContext<LocationContextType>('Location')

type Location = LocationContextType
interface Location extends URL {}

interface LocationProviderProps {
location?: Location
Expand Down
9 changes: 6 additions & 3 deletions packages/vite/src/streaming/createReactStreamingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ export const createReactStreamingHandler = async (
let currentRoute: RWRouteManifestItem | undefined
let parsedParams: any = {}

const urlPath = new URL(req.url).pathname
const currentUrl = new URL(req.url)

// @TODO validate this is correct
for (const route of routes) {
const { match, ...rest } = matchPath(route.pathDefinition, urlPath)
const { match, ...rest } = matchPath(
route.pathDefinition,
currentUrl.pathname,
)
if (match) {
currentRoute = route
parsedParams = rest
Expand Down Expand Up @@ -171,7 +174,7 @@ export const createReactStreamingHandler = async (
{
ServerEntry,
FallbackDocument,
urlPath,
currentUrl,
metaTags,
cssLinks,
isProd,
Expand Down
10 changes: 5 additions & 5 deletions packages/vite/src/streaming/streamHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { createServerInjectionTransform } from './transforms/serverInjectionTran
interface RenderToStreamArgs {
ServerEntry: ServerEntryType
FallbackDocument: React.FunctionComponent
urlPath: string
currentUrl: URL
metaTags: TagDescriptor[]
cssLinks: string[]
isProd: boolean
Expand Down Expand Up @@ -64,7 +64,7 @@ export async function reactRenderToStreamResponse(
const {
ServerEntry,
FallbackDocument,
urlPath,
currentUrl,
metaTags,
cssLinks,
isProd,
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function reactRenderToStreamResponse(

const timeoutTransform = createTimeoutTransform(timeoutHandle)

const renderRoot = (urlPath: string) => {
const renderRoot = (url: URL) => {
return React.createElement(
ServerAuthProvider,
{
Expand All @@ -112,7 +112,7 @@ export async function reactRenderToStreamResponse(
React.createElement(
LocationProvider,
{
location: { pathname: urlPath },
location: url,
},
React.createElement(
ServerHtmlProvider,
Expand Down Expand Up @@ -155,7 +155,7 @@ export async function reactRenderToStreamResponse(
},
}

const root = renderRoot(urlPath)
const root = renderRoot(currentUrl)

const reactStream: ReactDOMServerReadableStream =
await renderToReadableStream(root, renderToStreamOptions)
Expand Down

0 comments on commit eb2929f

Please sign in to comment.