Skip to content

Commit b565c9b

Browse files
committed
feat(devtools): use layer
1 parent 5bd5e28 commit b565c9b

5 files changed

Lines changed: 65 additions & 213 deletions

File tree

‎devtools/lib/robots/rpc.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useDevtoolsConnection } from 'nuxtseo-layer-devtools/composables/rpc'
2+
13
// The layer owns host fetch + route tracking and refreshes data on connect and
24
// on every route change; robots' state.ts watches refreshTime to reload
35
// debug + path data, so no module-level host access is needed here.

‎devtools/lib/robots/shiki.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LanguageRegistration } from 'shiki'
1+
import type { LanguageRegistration } from 'nuxtseo-layer-devtools/composables/shiki'
22
import { loadShiki as _loadShiki } from 'nuxtseo-layer-devtools/composables/shiki'
33

44
const robotsTxtLang: LanguageRegistration = {

‎devtools/lib/robots/state.ts‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ProductionDebugResponse } from './types'
2-
import { ref, watch } from 'vue'
3-
4-
export const mockProduction = useLocalStorage('nuxt-robots:mock-production', false)
2+
import { appFetch } from 'nuxtseo-layer-devtools/composables/rpc'
3+
import { isProductionMode, path, productionUrl, refreshTime } from 'nuxtseo-layer-devtools/composables/state'
4+
import { computed, ref, watch } from 'vue'
55

66
export const data = ref<{
77
indexable: boolean
@@ -23,24 +23,26 @@ export const pathDebugData = ref<{
2323
export const productionData = ref<ProductionDebugResponse | null>(null)
2424
export const productionLoading = ref(false)
2525

26+
/**
27+
* Single source of truth for the Overview, driven only by the header Local/Production
28+
* switch (`previewSource`). Local mode reads the dev debug endpoint; Production mode
29+
* reads the fetched-and-validated deployed robots.txt. Both expose `indexable`, `hints`,
30+
* `robotsTxt` and `validation`, so the Overview renders the same sections either way.
31+
*/
32+
export const overview = computed(() => isProductionMode.value ? productionData.value : data.value)
33+
2634
export async function refreshSources() {
2735
if (!appFetch.value || typeof appFetch.value !== 'function')
2836
return
29-
const query: Record<string, any> = {}
30-
if (mockProduction.value)
31-
query.mockProductionEnv = true
32-
data.value = await appFetch.value('/__robots__/debug.json', { query })
37+
data.value = await appFetch.value('/__robots__/debug.json')
3338
if (data.value?.siteConfig?.url)
3439
productionUrl.value = data.value.siteConfig.url
3540
}
3641

3742
export async function refreshPathDebug() {
3843
if (!appFetch.value || typeof appFetch.value !== 'function')
3944
return
40-
const req: Record<string, any> = { path: path.value }
41-
if (mockProduction.value)
42-
req.mockProductionEnv = true
43-
pathDebugData.value = await appFetch.value('/__robots__/debug-path.json', { query: req })
45+
pathDebugData.value = await appFetch.value('/__robots__/debug-path.json', { query: { path: path.value } })
4446
}
4547

4648
export async function refreshProductionData() {
@@ -49,7 +51,7 @@ export async function refreshProductionData() {
4951
productionLoading.value = true
5052

5153
// Try full debug endpoint first (requires debug: true in production)
52-
const remoteDebug = await appFetch.value('/__robots__/debug-production.json', {
54+
const remoteDebug: ProductionDebugResponse | null = await appFetch.value('/__robots__/debug-production.json', {
5355
query: { url: productionUrl.value, mode: 'debug' },
5456
}).catch(() => null)
5557
if (remoteDebug && !remoteDebug.error && remoteDebug.hasRemoteDebug) {
@@ -68,13 +70,13 @@ export async function refreshProductionData() {
6870
productionLoading.value = false
6971
}
7072

71-
// Re-fetch when env or path changes
72-
watch([mockProduction, path, appFetch, refreshTime], () => {
73+
// Re-fetch local debug when the inspected path or host data changes
74+
watch([path, appFetch, refreshTime], () => {
7375
refreshSources()
7476
refreshPathDebug()
7577
})
7678

77-
// Fetch production data when switching to production mode
79+
// Fetch production data the first time the header switch flips to Production
7880
watch(isProductionMode, (isProd) => {
7981
if (isProd && !productionData.value)
8082
refreshProductionData()

‎devtools/pages/robots.vue‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
import { isProductionMode } from 'nuxtseo-layer-devtools/composables/state'
23
import { computed, ref, watch } from 'vue'
34
import { navigateTo, useRoute } from '#imports'
45
import { loadShiki } from '../lib/robots/shiki'

0 commit comments

Comments
 (0)