mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
Compare commits
17 Commits
680831faba
...
17ee826ba3
Author | SHA1 | Date | |
---|---|---|---|
|
17ee826ba3 | ||
|
edc299a043 | ||
|
ad3ab4d310 | ||
|
9bf8465806 | ||
|
0861bdb7ba | ||
|
3d71ef18a2 | ||
|
0efca895ba | ||
|
5dfc163547 | ||
|
211900eb31 | ||
|
c62776b2e4 | ||
|
68a4d3b4ce | ||
|
acc23a0b72 | ||
|
4dad40c127 | ||
|
0214f703fa | ||
|
c94afe4fa0 | ||
|
f2643d8779 | ||
|
b48053a078 |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -248,7 +248,7 @@ jobs:
|
|||||||
TEST_PAYLOAD: ${{ matrix.payload }}
|
TEST_PAYLOAD: ${{ matrix.payload }}
|
||||||
SKIP_BUNDLE_SIZE: ${{ github.event_name != 'push' || matrix.env == 'dev' || matrix.builder == 'webpack' || matrix.context == 'default' || matrix.payload == 'js' || runner.os == 'Windows' }}
|
SKIP_BUNDLE_SIZE: ${{ github.event_name != 'push' || matrix.env == 'dev' || matrix.builder == 'webpack' || matrix.context == 'default' || matrix.payload == 'js' || runner.os == 'Windows' }}
|
||||||
|
|
||||||
- uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
|
- uses: codecov/codecov-action@985343d70564a82044c1b7fcb84c2fa05405c1a2 # v5.0.4
|
||||||
if: github.event_name != 'push' && matrix.env == 'built' && matrix.builder == 'vite' && matrix.context == 'default' && matrix.os == 'ubuntu-latest' && matrix.manifest == 'manifest-on'
|
if: github.event_name != 'push' && matrix.env == 'built' && matrix.builder == 'vite' && matrix.context == 'default' && matrix.os == 'ubuntu-latest' && matrix.manifest == 'manifest-on'
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
@ -21,8 +21,8 @@ Or follow the steps below to set up a new Nuxt project on your computer.
|
|||||||
<!-- markdownlint-disable-next-line MD001 -->
|
<!-- markdownlint-disable-next-line MD001 -->
|
||||||
#### Prerequisites
|
#### Prerequisites
|
||||||
|
|
||||||
- **Node.js** - [`v18.0.0`](https://nodejs.org/en) or newer
|
- **Node.js** - [`18.x`](https://nodejs.org/en) or newer (but we recommend the [active LTS release](https://github.com/nodejs/release#release-schedule))
|
||||||
- **Text editor** - We recommend [Visual Studio Code](https://code.visualstudio.com/) with the [official Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (previously known as Volar)
|
- **Text editor** - There is no IDE requirement, but we recommend [Visual Studio Code](https://code.visualstudio.com/) with the [official Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (previously known as Volar) or [WebStorm](https://www.jetbrains.com/webstorm/), which, along with [other JetBrains IDEs](https://www.jetbrains.com/ides/), offers great Nuxt support right out-of-the-box.
|
||||||
- **Terminal** - In order to run Nuxt commands
|
- **Terminal** - In order to run Nuxt commands
|
||||||
|
|
||||||
::note
|
::note
|
||||||
|
@ -32,7 +32,10 @@ Server only components use `<NuxtIsland>` under the hood
|
|||||||
- **type**: `Record<string, any>`
|
- **type**: `Record<string, any>`
|
||||||
- `source`: Remote source to call the island to render.
|
- `source`: Remote source to call the island to render.
|
||||||
- **type**: `string`
|
- **type**: `string`
|
||||||
- **dangerouslyLoadClientComponents**: Required to load components from a remote source.
|
- `useCache`: Use the cached payload if available
|
||||||
|
- **type**: `boolean`
|
||||||
|
- **default**: `true`
|
||||||
|
- **`dangerouslyLoadClientComponents`**: Required to load components from a remote source.
|
||||||
- **type**: `boolean`
|
- **type**: `boolean`
|
||||||
- **default**: `false`
|
- **default**: `false`
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
"devalue": "5.1.1",
|
"devalue": "5.1.1",
|
||||||
"eslint": "9.15.0",
|
"eslint": "9.15.0",
|
||||||
"eslint-plugin-no-only-tests": "3.3.0",
|
"eslint-plugin-no-only-tests": "3.3.0",
|
||||||
"eslint-plugin-perfectionist": "4.0.2",
|
"eslint-plugin-perfectionist": "4.0.3",
|
||||||
"eslint-typegen": "0.3.2",
|
"eslint-typegen": "0.3.2",
|
||||||
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
|
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
|
||||||
"happy-dom": "15.11.6",
|
"happy-dom": "15.11.6",
|
||||||
@ -118,7 +118,7 @@
|
|||||||
"vue-router": "4.4.5",
|
"vue-router": "4.4.5",
|
||||||
"vue-tsc": "2.1.10"
|
"vue-tsc": "2.1.10"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.13.2",
|
"packageManager": "pnpm@9.14.1",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^16.10.0 || >=18.0.0"
|
"node": "^16.10.0 || >=18.0.0"
|
||||||
},
|
},
|
||||||
|
@ -76,6 +76,14 @@ export default defineComponent({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* use the NuxtIslandResponse which has been cached if available
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
useCache: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
emits: ['error'],
|
emits: ['error'],
|
||||||
async setup (props, { slots, expose, emit }) {
|
async setup (props, { slots, expose, emit }) {
|
||||||
@ -250,13 +258,13 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (import.meta.client) {
|
if (import.meta.client) {
|
||||||
watch(props, debounce(() => fetchComponent(), 100), { deep: true })
|
watch(props, debounce(() => fetchComponent(!props.useCache), 100), { deep: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (import.meta.client && !instance.vnode.el && props.lazy) {
|
if (import.meta.client && !instance.vnode.el && props.lazy) {
|
||||||
fetchComponent()
|
fetchComponent(!instance.vnode.el && !props.useCache)
|
||||||
} else if (import.meta.server || !instance.vnode.el || !nuxtApp.payload.serverRendered) {
|
} else if (import.meta.server || !instance.vnode.el || !nuxtApp.payload.serverRendered) {
|
||||||
await fetchComponent()
|
await fetchComponent(!instance.vnode.el && !props.useCache)
|
||||||
} else if (selectiveClient && canLoadClientComponent.value) {
|
} else if (selectiveClient && canLoadClientComponent.value) {
|
||||||
await loadComponents(props.source, payloads.components)
|
await loadComponents(props.source, payloads.components)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ export const createServerComponent = (name: string) => {
|
|||||||
return defineComponent({
|
return defineComponent({
|
||||||
name,
|
name,
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: { lazy: Boolean },
|
props: { lazy: Boolean, useCache: { type: Boolean, default: true } },
|
||||||
emits: ['error'],
|
emits: ['error'],
|
||||||
setup (props, { attrs, slots, expose, emit }) {
|
setup (props, { attrs, slots, expose, emit }) {
|
||||||
const vm = getCurrentInstance()
|
const vm = getCurrentInstance()
|
||||||
@ -22,6 +22,7 @@ export const createServerComponent = (name: string) => {
|
|||||||
return h(NuxtIsland, {
|
return h(NuxtIsland, {
|
||||||
name,
|
name,
|
||||||
lazy: props.lazy,
|
lazy: props.lazy,
|
||||||
|
useCache: props.useCache,
|
||||||
props: attrs,
|
props: attrs,
|
||||||
scopeId: vm?.vnode.scopeId,
|
scopeId: vm?.vnode.scopeId,
|
||||||
ref: islandRef,
|
ref: islandRef,
|
||||||
@ -40,7 +41,7 @@ export const createIslandPage = (name: string) => {
|
|||||||
name,
|
name,
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: { lazy: Boolean },
|
props: { lazy: Boolean },
|
||||||
async setup (props, { slots, expose }) {
|
async setup(props, { slots, expose }) {
|
||||||
const islandRef = ref<null | typeof NuxtIsland>(null)
|
const islandRef = ref<null | typeof NuxtIsland>(null)
|
||||||
|
|
||||||
expose({
|
expose({
|
||||||
|
@ -114,8 +114,8 @@ importers:
|
|||||||
specifier: 3.3.0
|
specifier: 3.3.0
|
||||||
version: 3.3.0
|
version: 3.3.0
|
||||||
eslint-plugin-perfectionist:
|
eslint-plugin-perfectionist:
|
||||||
specifier: 4.0.2
|
specifier: 4.0.3
|
||||||
version: 4.0.2(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
version: 4.0.3(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
||||||
eslint-typegen:
|
eslint-typegen:
|
||||||
specifier: 0.3.2
|
specifier: 0.3.2
|
||||||
version: 0.3.2(eslint@9.15.0(jiti@2.4.0))
|
version: 0.3.2(eslint@9.15.0(jiti@2.4.0))
|
||||||
@ -4373,8 +4373,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-brcKcxGnISN2CcVhXJ/kEQlNa0MEfGRtwKtWA16SkqXHKitaKIMrfemJKLKX1YqDU5C/5JY3PvZXd5jEW04e0Q==}
|
resolution: {integrity: sha512-brcKcxGnISN2CcVhXJ/kEQlNa0MEfGRtwKtWA16SkqXHKitaKIMrfemJKLKX1YqDU5C/5JY3PvZXd5jEW04e0Q==}
|
||||||
engines: {node: '>=5.0.0'}
|
engines: {node: '>=5.0.0'}
|
||||||
|
|
||||||
eslint-plugin-perfectionist@4.0.2:
|
eslint-plugin-perfectionist@4.0.3:
|
||||||
resolution: {integrity: sha512-zWdgyg2SdHqhp/P9d9vKwo5qD9is28xMAGzBslHqkZz5mVIikjyz1qvuJ4yS7Wrsf4KlbGorORefb4Kbe7Puzg==}
|
resolution: {integrity: sha512-CyafnreF6boy4lf1XaF72U8NbkwrfjU/mOf1y6doaDMS9zGXhUU1DSk+ZPf/rVwCf1PL1m+rhHqFs+IcB8kDmA==}
|
||||||
engines: {node: ^18.0.0 || >=20.0.0}
|
engines: {node: ^18.0.0 || >=20.0.0}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
eslint: '>=8.0.0'
|
eslint: '>=8.0.0'
|
||||||
@ -11519,7 +11519,7 @@ snapshots:
|
|||||||
|
|
||||||
eslint-plugin-no-only-tests@3.3.0: {}
|
eslint-plugin-no-only-tests@3.3.0: {}
|
||||||
|
|
||||||
eslint-plugin-perfectionist@4.0.2(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3):
|
eslint-plugin-perfectionist@4.0.3(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@typescript-eslint/types': 8.15.0
|
'@typescript-eslint/types': 8.15.0
|
||||||
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { beforeEach } from 'node:test'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import { describe, expect, it, vi } from 'vitest'
|
|
||||||
import { defineComponent, h, nextTick, popScopeId, pushScopeId } from 'vue'
|
import { defineComponent, h, nextTick, popScopeId, pushScopeId } from 'vue'
|
||||||
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
||||||
import { createServerComponent } from '../../packages/nuxt/src/components/runtime/server-component'
|
import { createServerComponent } from '../../packages/nuxt/src/components/runtime/server-component'
|
||||||
@ -34,6 +33,11 @@ function expectNoConsoleIssue () {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
consoleError.mockClear()
|
consoleError.mockClear()
|
||||||
consoleWarn.mockClear()
|
consoleWarn.mockClear()
|
||||||
|
useNuxtApp().payload.data = {}
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
if (vi.isMockFunction(fetch)) { vi.mocked(fetch).mockReset() }
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('runtime server component', () => {
|
describe('runtime server component', () => {
|
||||||
@ -135,6 +139,22 @@ describe('runtime server component', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('expect NuxtIsland to have parent scopeId', async () => {
|
it('expect NuxtIsland to have parent scopeId', async () => {
|
||||||
|
const stubFetch = vi.fn(() => {
|
||||||
|
return {
|
||||||
|
id: '1234',
|
||||||
|
html: `<div data-island-uid>hello<div data-island-uid="not-to-be-replaced" data-island-component="r"></div></div>`,
|
||||||
|
head: {
|
||||||
|
link: [],
|
||||||
|
style: [],
|
||||||
|
},
|
||||||
|
json () {
|
||||||
|
return this
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
vi.stubGlobal('fetch', stubFetch)
|
||||||
|
|
||||||
const wrapper = await mountSuspended(defineComponent({
|
const wrapper = await mountSuspended(defineComponent({
|
||||||
render () {
|
render () {
|
||||||
pushScopeId('data-v-654e2b21')
|
pushScopeId('data-v-654e2b21')
|
||||||
@ -330,6 +350,63 @@ describe('client components', () => {
|
|||||||
<!--teleport end-->"
|
<!--teleport end-->"
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
vi.mocked(fetch).mockReset()
|
||||||
expectNoConsoleIssue()
|
expectNoConsoleIssue()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('reuse paylaod', () => {
|
||||||
|
let count = 0
|
||||||
|
|
||||||
|
const stubFetch = () => {
|
||||||
|
count++
|
||||||
|
return {
|
||||||
|
id: '123',
|
||||||
|
html: `<div>${count.toString()}</div>`,
|
||||||
|
state: {},
|
||||||
|
head: {
|
||||||
|
link: [],
|
||||||
|
style: [],
|
||||||
|
},
|
||||||
|
json () {
|
||||||
|
return this
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
count = 0
|
||||||
|
vi.mocked(fetch).mockReset()
|
||||||
|
vi.stubGlobal('fetch', vi.fn(stubFetch))
|
||||||
|
})
|
||||||
|
it('expect payload to be reused', async () => {
|
||||||
|
const component1 = await mountSuspended(createServerComponent('reuseCache'))
|
||||||
|
expect(fetch).toHaveBeenCalledOnce()
|
||||||
|
expect(component1.html()).toBe('<div>1</div>')
|
||||||
|
await component1.unmount()
|
||||||
|
expect(fetch).toHaveBeenCalledOnce()
|
||||||
|
const component2 = await mountSuspended(createServerComponent('reuseCache'))
|
||||||
|
expect(component2.html()).toBe('<div>1</div>')
|
||||||
|
})
|
||||||
|
it('expect to re-fetch the island', async () => {
|
||||||
|
const component = await mountSuspended(createServerComponent('withoutCache'), {
|
||||||
|
props: {
|
||||||
|
useCache: false,
|
||||||
|
onError (e) {
|
||||||
|
console.log(e)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await nextTick()
|
||||||
|
expect(fetch).toHaveBeenCalledOnce()
|
||||||
|
expect(component.html()).toBe('<div>1</div>')
|
||||||
|
await component.unmount()
|
||||||
|
const component2 = await mountSuspended(createServerComponent('withoutCache'), {
|
||||||
|
props: {
|
||||||
|
useCache: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(fetch).toHaveBeenCalledTimes(2)
|
||||||
|
expect(component2.html()).toBe('<div>2</div>')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user