11import 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
66export const data = ref < {
77 indexable : boolean
@@ -23,24 +23,26 @@ export const pathDebugData = ref<{
2323export const productionData = ref < ProductionDebugResponse | null > ( null )
2424export 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+
2634export 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
3742export 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
4648export 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
7880watch ( isProductionMode , ( isProd ) => {
7981 if ( isProd && ! productionData . value )
8082 refreshProductionData ( )
0 commit comments