Skip to content

Commit

Permalink
Pass the full page object: See discussion #1863
Browse files Browse the repository at this point in the history
  • Loading branch information
james-em committed Apr 19, 2024
1 parent ca7e7cb commit 6662cd7
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export class Router {
preserveState?: PreserveStateOption
} = {},
): Promise<void> {
return Promise.resolve(this.resolveComponent(page.component)).then((component) => {
return Promise.resolve(this.resolveComponent(page.component, page)).then((component) => {
if (visitId === this.visitId) {
page.scrollRegions = page.scrollRegions || []
page.rememberedState = page.rememberedState || {}
Expand Down Expand Up @@ -481,7 +481,7 @@ export class Router {
if (event.state !== null) {
const page = event.state
const visitId = this.createVisitId()
Promise.resolve(this.resolveComponent(page.component)).then((component) => {
Promise.resolve(this.resolveComponent(page.component, page)).then((component) => {
if (visitId === this.visitId) {
this.page = page
this.swapComponent({ component, page, preserveState: false }).then(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface Page<SharedProps extends PageProps = PageProps> {
rememberedState: Record<string, unknown>
}

export type PageResolver = (name: string) => Component
export type PageResolver = (name: string, page: Page) => Component

export type PageHandler = ({
component,
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/createInertiaApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ export default async function createInertiaApp<SharedProps extends PageProps = P
const el = isServer ? null : document.getElementById(id)
const initialPage = page || JSON.parse(el.dataset.page)
// @ts-expect-error
const resolveComponent = (name) => Promise.resolve(resolve(name)).then((module) => module.default || module)
const resolveComponent = (name, page) => Promise.resolve(resolve(name, page)).then((module) => module.default || module)

let head = []

const reactApp = await resolveComponent(initialPage.component).then((initialComponent) => {
const reactApp = await resolveComponent(initialPage.component, initialPage).then((initialComponent) => {
return setup({
// @ts-expect-error
el,
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/createInertiaApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro
const isServer = typeof window === 'undefined'
const el = isServer ? null : document.getElementById(id)
const initialPage = page || JSON.parse(el.dataset.page)
const resolveComponent = (name) => Promise.resolve(resolve(name))
const resolveComponent = (name, page) => Promise.resolve(resolve(name, page))

await resolveComponent(initialPage.component).then((initialComponent) => {
await resolveComponent(initialPage.component, initialPage).then((initialComponent) => {
store.set({
component: initialComponent,
page: initialPage,
Expand Down
2 changes: 1 addition & 1 deletion packages/vue2/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useForm from './useForm'
export interface InertiaProps {
initialPage: Page
initialComponent?: object
resolveComponent?: (name: string) => Component
resolveComponent?: (name: string, page: Page) => Component
titleCallback?: (title: string) => string
onHeadUpdate?: (elements: string[]) => void
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vue2/src/createInertiaApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App, { InertiaApp, InertiaProps, plugin } from './app'

interface CreateInertiaAppProps {
id?: string
resolve: (name: string) => Component | Promise<Component> | { default: Component }
resolve: (name: string, page: Page) => Component | Promise<Component> | { default: Component }
setup: (props: {
el: Element
App: InertiaApp
Expand Down Expand Up @@ -40,11 +40,11 @@ export default async function createInertiaApp({
const el = isServer ? null : document.getElementById(id)
const initialPage = page || JSON.parse(el.dataset.page)
// @ts-expect-error
const resolveComponent = (name) => Promise.resolve(resolve(name)).then((module) => module.default || module)
const resolveComponent = (name, page) => Promise.resolve(resolve(name, page)).then((module) => module.default || module)

let head = []

const vueApp = await resolveComponent(initialPage.component).then((initialComponent) => {
const vueApp = await resolveComponent(initialPage.component, initialPage).then((initialComponent) => {
return setup({
el,
App,
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import useForm from './useForm'
export interface InertiaAppProps {
initialPage: Page
initialComponent?: object
resolveComponent?: (name: string) => DefineComponent | Promise<DefineComponent>
resolveComponent?: (name: string, page: Page) => DefineComponent | Promise<DefineComponent>
titleCallback?: (title: string) => string
onHeadUpdate?: (elements: string[]) => void
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vue3/src/createInertiaApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App, { InertiaApp, InertiaAppProps, plugin } from './app'

interface CreateInertiaAppProps {
id?: string
resolve: (name: string) => DefineComponent | Promise<DefineComponent> | { default: DefineComponent }
resolve: (name: string, page: Page) => DefineComponent | Promise<DefineComponent> | { default: DefineComponent }
setup: (props: { el: Element; App: InertiaApp; props: InertiaAppProps; plugin: Plugin }) => void | VueApp
title?: (title: string) => string
progress?:
Expand All @@ -31,11 +31,11 @@ export default async function createInertiaApp({
const isServer = typeof window === 'undefined'
const el = isServer ? null : document.getElementById(id)
const initialPage = page || JSON.parse(el.dataset.page)
const resolveComponent = (name) => Promise.resolve(resolve(name)).then((module) => module.default || module)
const resolveComponent = (name, page) => Promise.resolve(resolve(name, page)).then((module) => module.default || module)

let head = []

const vueApp = await resolveComponent(initialPage.component).then((initialComponent) => {
const vueApp = await resolveComponent(initialPage.component, initialPage).then((initialComponent) => {
return setup({
el,
App,
Expand Down

0 comments on commit 6662cd7

Please sign in to comment.