Skip to content

Commit

Permalink
Merge branch 'feat/gql-auth-context-cookie' of github.com:dac09/redwo…
Browse files Browse the repository at this point in the history
…od into feat/gql-auth-context-cookie

* 'feat/gql-auth-context-cookie' of github.com:dac09/redwood:
  chore(location): Accept URL-like object (redwoodjs#10467)
  • Loading branch information
dac09 committed Apr 16, 2024
2 parents ad0f3cc + 147c609 commit 42627d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
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

0 comments on commit 42627d7

Please sign in to comment.