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

fix(nuxt): don't add an extra baseURL on server useRequestURL #25765

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/nuxt/src/app/composables/url.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { getRequestURL } from 'h3'
import { joinURL } from 'ufo'
import { useRuntimeConfig } from '../nuxt'
import { useRequestEvent } from './ssr'

/** @since 3.5.0 */
export function useRequestURL () {
if (import.meta.server) {
const url = getRequestURL(useRequestEvent()!)
url.pathname = joinURL(useRuntimeConfig().app.baseURL, url.pathname)
return url
return getRequestURL(useRequestEvent()!)
}
return new URL(window.location.href)
}
8 changes: 5 additions & 3 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ describe('nuxt links', () => {
await page.close()
})

it('expect scroll to top on routes with same component',
it('expect scroll to top on routes with same component',
async () => {
// #22402
const page = await createPage('/big-page-1', {
Expand All @@ -616,12 +616,12 @@ describe('nuxt links', () => {
await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, `/big-page-1`)
expect(await page.evaluate(() => window.scrollY)).toBe(0)
await page.close()
},
},
// Flaky behavior when using Webpack
{ retry: isWebpack ? 10 : 0 }
)

it('expect scroll to top on nested pages',
it('expect scroll to top on nested pages',
async () => {
// #20523
const page = await createPage('/nested/foo/test', {
Expand Down Expand Up @@ -1722,6 +1722,8 @@ describe.skipIf(isDev())('dynamic paths', () => {
(isWebpack && url === '/public.svg')
).toBeTruthy()
}

expect(await $fetch('/foo/url')).toContain('path: /foo/url')
})

it('should allow setting relative baseURL', async () => {
Expand Down