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

Pass the full page object to resolve component #1864

Closed
wants to merge 1 commit into from
Closed
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
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
Loading