Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(location): Accept URL-like object #10467

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/router/src/location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import { createNamedContext } from './createNamedContext'
import { gHistory } from './history'
import type { TrailingSlashesTypes } from './util'

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

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

interface Location extends URL {}
type Location = LocationContextType

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

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

// @TODO validate this is correct
for (const route of routes) {
const { match, ...rest } = matchPath(
route.pathDefinition,
currentUrl.pathname,
)
const { match, ...rest } = matchPath(route.pathDefinition, urlPath)
if (match) {
currentRoute = route
parsedParams = rest
Expand Down Expand Up @@ -174,7 +171,7 @@ export const createReactStreamingHandler = async (
{
ServerEntry,
FallbackDocument,
currentUrl,
urlPath,
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
currentUrl: URL
urlPath: string
metaTags: TagDescriptor[]
cssLinks: string[]
isProd: boolean
Expand Down Expand Up @@ -64,7 +64,7 @@ export async function reactRenderToStreamResponse(
const {
ServerEntry,
FallbackDocument,
currentUrl,
urlPath,
metaTags,
cssLinks,
isProd,
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function reactRenderToStreamResponse(

const timeoutTransform = createTimeoutTransform(timeoutHandle)

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

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

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