Skip to content
Open
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
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,34 @@ jobs:
- run: pnpm test:types
- run: pnpm lint
- run: pnpm test

# Nuxt 5 is still a pre-release: this job tracks it and may fail without blocking merges.
nuxt-5:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
- uses: pnpm/action-setup@6e7bdbda5fe05107efc88b23b7ed00aa05f84ca0
name: Install pnpm
- name: Install Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f
with:
node-version: 24.22.0
cache: 'pnpm'
- name: Point the workspace at the Nuxt 5 nightly
run: |
sed -i \
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
-e "s#^ nuxt: .*# nuxt: npm:nuxt-nightly@5x#" \
-e "s#^ '@nuxt/kit': .*# '@nuxt/kit': npm:@nuxt/kit-nightly@5x#" \
-e "s#^ '@nuxt/schema': .*# '@nuxt/schema': npm:@nuxt/schema-nightly@5x#" \
-e "s#^ '@nuxt/vite-builder': .*# '@nuxt/vite-builder': npm:@nuxt/vite-builder-nightly@5x#" \
-e "s#^ '@nuxt/nitro-server': .*# '@nuxt/nitro-server': npm:@nuxt/nitro-server-nightly@5x#" \
pnpm-workspace.yaml
cat pnpm-workspace.yaml
# fail loudly if the overrides block drifted and nothing was substituted
test "$(grep -c -- '-nightly@5x' pnpm-workspace.yaml)" -eq 5
- run: pnpm install --no-frozen-lockfile
- run: pnpm dev:prepare
- run: pnpm prepack
- run: pnpm test:types
- run: pnpm test
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

2 changes: 1 addition & 1 deletion client/.nuxtrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
imports.autoImport=true
setups.@nuxt/test-utils="4.3.3"
setups.@nuxt/test-utils="4.4.0"
90 changes: 70 additions & 20 deletions client/app/app.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<script setup lang="ts">
import { useDevtoolsClient, onDevtoolsClientConnected } from '@nuxt/devtools-kit/iframe-client'
import type { HintsClientFunctions, HintsServerFunctions } from '../../src/runtime/core/rpc-types'
import { RPC_NAMESPACE } from '../../src/runtime/core/rpc-types'
import type { HydrationMismatchPayload, LocalHydrationMismatch } from '../../src/runtime/hydration/types'
import type { HydrationMismatchResponse, HydrationMismatchPayload, LocalHydrationMismatch } from '../../src/runtime/hydration/types'
import type { ComponentLazyLoadData } from '../../src/runtime/lazy-load/schema'
import { ComponentLazyLoadDataSchema } from '../../src/runtime/lazy-load/schema'
import type { HtmlValidateReport } from '../../src/runtime/html-validate/types'
import { CLIENT_RPC_NAMES, SERVER_RPC_NAMES } from '../../src/runtime/core/rpc-types'
import { useDevtoolsHost, useDevtoolsStatus, useHintsRpc, type HintsRpc, type HostClient } from './composables/devtools'
import { parse } from 'valibot'

const client = useDevtoolsClient()
const host = useDevtoolsHost()
const rpc = useHintsRpc()
const status = useDevtoolsStatus()
const connected = computed(() => Boolean(rpc.value && host.value))
const lost = computed(() => status.value === 'disconnected' || status.value === 'error' || status.value === 'unauthorized')

function reload() {
window.location.reload()
}

const hydrationMismatches = ref<(HydrationMismatchPayload | LocalHydrationMismatch)[]>([])
const lazyLoadHints = ref<ComponentLazyLoadData[]>([])
Expand All @@ -19,7 +26,15 @@ nuxtApp.provide('hydrationMismatches', hydrationMismatches)
nuxtApp.provide('lazyLoadHints', lazyLoadHints)
nuxtApp.provide('htmlValidateReports', htmlValidateReports)

onDevtoolsClientConnected((client) => {
// one-shot: `immediate` can fire synchronously, before a `stop` handle exists
let isSetUp = false
watch(connected, (isConnected) => {
if (isSetUp || !isConnected || !rpc.value || !host.value) return
isSetUp = true
setup(rpc.value, host.value)
}, { immediate: true })

function setup(rpc: HintsRpc, host: HostClient) {
const hydrationTombstones = new Set<string>()
const lazyLoadTombstones = new Set<string>()
const htmlValidateTombstones = new Set<string>()
Expand Down Expand Up @@ -59,19 +74,30 @@ onDevtoolsClientConnected((client) => {
}
}

const rpc = client.devtools.extendClientRpc<HintsServerFunctions, HintsClientFunctions>(RPC_NAMESPACE, {
onHydrationMismatch(mismatch: HydrationMismatchPayload) {
// Broadcasts from the Nuxt process, registered as `nuxt-hints:on-*` client events
rpc.register({
name: CLIENT_RPC_NAMES.onHydrationMismatch,
type: 'event',
handler(mismatch: HydrationMismatchPayload) {
if (!hydrationInitialSyncDone) {
bufferedHydrationMismatches.push(mismatch)
return
}
applyHydrationMismatch(mismatch)
},
onHydrationCleared(ids: string[]) {
})
rpc.register({
name: CLIENT_RPC_NAMES.onHydrationCleared,
type: 'event',
handler(ids: string[]) {
ids.forEach(id => hydrationTombstones.add(id))
hydrationMismatches.value = hydrationMismatches.value.filter(m => !ids.includes(m.id))
},
onLazyLoadReport(data: ComponentLazyLoadData) {
})
rpc.register({
name: CLIENT_RPC_NAMES.onLazyLoadReport,
type: 'event',
handler(data: ComponentLazyLoadData) {
try {
const validated = parse(ComponentLazyLoadDataSchema, data)
if (!lazyLoadInitialSyncDone) {
Expand All @@ -84,30 +110,42 @@ onDevtoolsClientConnected((client) => {
console.warn('[hints] Ignoring malformed lazy-load report', data)
}
},
onLazyLoadCleared(id: string) {
})
rpc.register({
name: CLIENT_RPC_NAMES.onLazyLoadCleared,
type: 'event',
handler(id: string) {
lazyLoadTombstones.add(id)
lazyLoadHints.value = lazyLoadHints.value.filter(entry => entry.id !== id)
},
onHtmlValidateReport(report: HtmlValidateReport) {
})
rpc.register({
name: CLIENT_RPC_NAMES.onHtmlValidateReport,
type: 'event',
handler(report: HtmlValidateReport) {
if (!htmlValidateInitialSyncDone) {
bufferedHtmlValidateReports.push(report)
return
}
applyHtmlValidateReport(report)
},
onHtmlValidateDeleted(id: string) {
})
rpc.register({
name: CLIENT_RPC_NAMES.onHtmlValidateDeleted,
type: 'event',
handler(id: string) {
htmlValidateTombstones.add(id)
htmlValidateReports.value = htmlValidateReports.value.filter(report => report.id !== id)
},
})

// Hydration: seed from host payload and fetch from server via RPC
if (useHintsFeature('hydration')) {
if (client.host?.nuxt?.payload?.__hints?.hydration) {
hydrationMismatches.value = client.host.nuxt.payload.__hints.hydration
if (host.nuxt?.payload?.__hints?.hydration) {
hydrationMismatches.value = host.nuxt.payload.__hints.hydration
.filter(mismatch => !hydrationTombstones.has(mismatch.id))
}
rpc.getHydrationMismatches().then((data) => {
rpc.call(SERVER_RPC_NAMES.getHydrationMismatches).then((data: HydrationMismatchResponse) => {
data.mismatches
.filter(mismatch => !hydrationTombstones.has(mismatch.id))
.forEach(mismatch => applyHydrationMismatch(mismatch))
Expand All @@ -122,7 +160,7 @@ onDevtoolsClientConnected((client) => {

// Lazy load: fetch from server via RPC
if (useHintsFeature('lazyLoad')) {
rpc.getLazyLoadHints().then((data) => {
rpc.call(SERVER_RPC_NAMES.getLazyLoadHints).then((data: ComponentLazyLoadData[] | undefined) => {
;(data ?? [])
.filter(entry => !lazyLoadTombstones.has(entry.id))
.forEach(entry => applyLazyLoadHint(entry))
Expand All @@ -137,7 +175,7 @@ onDevtoolsClientConnected((client) => {

// HTML validate: fetch from server via RPC
if (useHintsFeature('htmlValidate')) {
rpc.getHtmlValidateReports().then((data) => {
rpc.call(SERVER_RPC_NAMES.getHtmlValidateReports).then((data: HtmlValidateReport[] | undefined) => {
;(data ?? [])
.filter(report => !htmlValidateTombstones.has(report.id))
.forEach(report => applyHtmlValidateReport(report))
Expand All @@ -149,12 +187,24 @@ onDevtoolsClientConnected((client) => {
bufferedHtmlValidateReports.length = 0
})
}
})
}
</script>

<template>
<div>
<NuxtLayout v-if="client">
<div
v-if="lost"
class="n-panel-grids-center"
>
<div class="flex flex-col items-center gap-3 text-lg">
<div class="i-carbon-plug text-4xl op50" />
<span>Lost connection to the DevTools server ({{ status }})</span>
<Button @click="reload">
Reload
</Button>
</div>
</div>
<NuxtLayout v-else-if="connected">
<NuxtPage />
</NuxtLayout>
<NLoading v-else />
Expand Down
5 changes: 5 additions & 0 deletions client/app/components/n/Badge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<span class="inline-flex items-center rounded px-1.5 py-0.5 text-xs bg-neutral-500/10 text-neutral-600 dark:text-neutral-300">
<slot />
</span>
</template>
29 changes: 29 additions & 0 deletions client/app/components/n/Button.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script setup lang="ts">
const props = withDefaults(defineProps<{
size?: 'small' | 'medium'
quaternary?: boolean
disabled?: boolean
}>(), {
size: 'medium',
quaternary: false,
disabled: false,
})

const classes = computed(() => [
props.quaternary
? 'border-transparent bg-transparent'
: 'border-base n-bg-base',
props.size === 'small' ? 'px-2 py-0.5 text-xs' : 'px-3 py-1 text-sm',
])
</script>

<template>
<button
type="button"
class="inline-flex items-center gap-1 border rounded cursor-pointer n-transition text-neutral-700 dark:text-neutral-200 hover:bg-neutral-500/10 disabled:op-50 disabled:cursor-not-allowed"
:class="classes"
:disabled="disabled"
>
<slot />
</button>
</template>
5 changes: 5 additions & 0 deletions client/app/components/n/Card.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div class="border border-base rounded-lg n-bg-base shadow-sm n-transition">
<slot />
</div>
</template>
9 changes: 9 additions & 0 deletions client/app/components/n/Loading.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<div class="flex flex-col items-center justify-center gap-2 h-screen text-neutral-500">
<Icon
name="carbon:circle-dash"
class="text-3xl animate-spin"
/>
<slot>Loading...</slot>
</div>
</template>
36 changes: 36 additions & 0 deletions client/app/components/n/Tip.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script setup lang="ts">
type TipType = 'default' | 'info' | 'success' | 'warning' | 'error'

const props = withDefaults(defineProps<{
type?: TipType
size?: 'small' | 'medium'
bordered?: boolean
}>(), {
type: 'default',
size: 'medium',
bordered: true,
})

const TYPE_CLASSES: Record<TipType, string> = {
default: 'text-neutral-600 dark:text-neutral-300 bg-neutral-500/10 border-neutral-500/25',
info: 'text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/25',
success: 'text-green-600 dark:text-green-400 bg-green-500/10 border-green-500/25',
warning: 'text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/25',
error: 'text-red-600 dark:text-red-400 bg-red-500/10 border-red-500/25',
}

const classes = computed(() => [
TYPE_CLASSES[props.type],
props.bordered ? 'border' : 'border-0',
props.size === 'small' ? 'px-2 py-0.5 text-xs' : 'px-4 py-2 text-sm',
])
</script>

<template>
<div
class="inline-flex items-center gap-1 rounded"
:class="classes"
>
<slot />
</div>
</template>
Loading
Loading