-
Notifications
You must be signed in to change notification settings - Fork 504
Add router configuration for displaying modal on non-Inertia responses #2332
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Page, PageProps, PageResolver, router, setupProgress } from '@inertiajs/core' | ||
import { Page, PageProps, PageResolver, router, setupModal, setupProgress } from '@inertiajs/core' | ||
import { ComponentType, FunctionComponent, Key, ReactElement, ReactNode, createElement } from 'react' | ||
import { renderToString } from 'react-dom/server' | ||
import App from './App' | ||
|
@@ -30,6 +30,7 @@ export type SetupOptions<ElementType, SharedProps extends PageProps> = { | |
type BaseInertiaAppOptions = { | ||
title?: HeadManagerTitleCallback | ||
resolve: PageResolver | ||
showModalOnNonInertiaResponse?: boolean | ||
} | ||
|
||
type CreateInertiaAppSetupReturnType = ReactInstance | void | ||
|
@@ -71,6 +72,7 @@ export default async function createInertiaApp<SharedProps extends PageProps = P | |
progress = {}, | ||
page, | ||
render, | ||
showModalOnNonInertiaResponse = true, | ||
}: InertiaAppOptionsForCSR<SharedProps> | InertiaAppOptionsForSSR<SharedProps>): Promise< | ||
CreateInertiaAppSetupReturnType | CreateInertiaAppSSRContent | ||
> { | ||
|
@@ -82,6 +84,10 @@ export default async function createInertiaApp<SharedProps extends PageProps = P | |
|
||
let head = [] | ||
|
||
if (!isServer) { | ||
setupModal({ showOnNonInertiaResponse: showModalOnNonInertiaResponse }) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternative Approach: if we wanted to follow the same "API" used for the progress configs, we could instead have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A usage example of the alternative proposal would then look like: createInertiaApp({
modal: {
showOnNonInertiaResponse: false
},
progress: {
delay: 300,
color: '#29d'
},
resolve: (name) => import(`./Pages/${name}`),
setup({ el, App, props }) {
render(<App {...props} />, el)
}
}) |
||
|
||
const reactApp = await Promise.all([ | ||
resolveComponent(initialPage.component), | ||
router.decryptHistory().catch(() => {}), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this logic could be moved inside the
modal.show
so the caller doesn't need to know about this config or any business rule