Skip to content

Commit c5e32fb

Browse files
committed
fix(messaging): navigation for non markdown files
1 parent e501ba7 commit c5e32fb

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/runtime/composables/useStudio.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createApp } from 'vue'
2-
import type { ParsedContent } from '@nuxt/content/dist/runtime/types'
2+
import type { ParsedContent } from '@nuxt/content'
33
import type { RouteLocationNormalized } from 'vue-router'
44
import type { AppConfig } from 'nuxt/schema'
55
import ContentPreviewMode from '../components/ContentPreviewMode.vue'
@@ -180,15 +180,23 @@ export const useStudio = () => {
180180
switch (type) {
181181
case 'nuxt-studio:editor:file-selected': {
182182
const content = await findContentItem(payload.path)
183-
if (!content) {
183+
if (!content || content._partial) {
184184
// Do not navigate to another page if content is not found
185185
// This makes sure that user stays on the same page when navigation through directories in the editor
186+
// Also, We should not navigate if content is a partial
187+
return
186188
}
187-
else if (content._partial || !String(payload.path).endsWith('.md')) {
188-
// Partials and non-markdown files should use as helpers for other content files, like `_dir.yml`
189-
// We should not navigate if content is a partial or non-markdown file
189+
190+
// Ensure that the content is related to a valid route for non markdown files
191+
if (!String(payload.path).endsWith('.md')) {
192+
const resolvedRoute = router.resolve(content._path)
193+
if (!resolvedRoute || !resolvedRoute.matched || resolvedRoute.matched.length === 0) {
194+
return
195+
}
190196
}
191-
else if (content._path !== useRoute().path) {
197+
198+
// Navigate to the selected content
199+
if (content._path !== useRoute().path) {
192200
editorSelectedPath.value = content._path!
193201
router.push(content._path!)
194202
}
@@ -235,6 +243,7 @@ export const useStudio = () => {
235243
route.meta.studio_page_contentId = page?._id
236244
})
237245

246+
// @ts-expect-error custom hook
238247
nuxtApp.hook('nuxt-studio:preview:ready', () => {
239248
window.parent.postMessage({
240249
type: 'nuxt-studio:preview:ready',

0 commit comments

Comments
 (0)