Skip to content

Commit 7b42bcb

Browse files
committed
Merge branch 'main' into 1.x
2 parents b2daa54 + 5000d42 commit 7b42bcb

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
204204

205205
const isAddressInfo = (x: string|AddressInfo|null|undefined): x is AddressInfo => typeof x === 'object'
206206
if (isAddressInfo(address)) {
207-
viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig)
207+
viteDevServerUrl = userConfig.server?.origin ? userConfig.server.origin as DevServerUrl : resolveDevServerUrl(address, server.config, userConfig)
208208
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl)
209209

210210
setTimeout(() => {

src/inertia-helpers/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
export async function resolvePageComponent<T>(path: string, pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T> {
2-
const page = pages[path]
1+
export async function resolvePageComponent<T>(path: string|string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T> {
2+
for (const p of (Array.isArray(path) ? path : [path])) {
3+
const page = pages[p]
34

4-
if (typeof page === 'undefined') {
5-
throw new Error(`Page not found: ${path}`)
5+
if (typeof page === 'undefined') {
6+
continue
7+
}
8+
9+
return typeof page === 'function' ? page() : page
610
}
711

8-
return typeof page === 'function' ? page() : page
12+
throw new Error(`Page not found: ${path}`)
913
}

tests/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,9 @@ describe('inertia-helpers', () => {
376376
const file = await resolvePageComponent<{ default: string }>(path, import.meta.glob('./__data__/*.ts', { eager: true }))
377377
expect(file.default).toBe('Dummy File')
378378
})
379+
380+
it('accepts array of paths', async () => {
381+
const file = await resolvePageComponent<{ default: string }>(['missing-page', path], import.meta.glob('./__data__/*.ts', { eager: true }), path)
382+
expect(file.default).toBe('Dummy File')
383+
})
379384
})

0 commit comments

Comments
 (0)