[\s\S]*?)<\/template>)?[\s\S]*?<\/(?:dev-only|DevOnly)>/g
return {
name: 'nuxt:server-devonly:transform',
@@ -29,7 +29,7 @@ export const DevOnlyPlugin = createUnplugin((options: DevOnlyPluginOptions) => {
const s = new MagicString(code)
const strippedCode = stripLiteral(code)
for (const match of strippedCode.matchAll(DEVONLY_COMP_RE) || []) {
- s.remove(match.index!, match.index! + match[0].length)
+ s.overwrite(match.index!, match.index! + match[0].length, match.groups?.fallback || '')
}
if (s.hasChanged()) {
diff --git a/test/basic.test.ts b/test/basic.test.ts
index c7d2a94d0071..322437db161c 100644
--- a/test/basic.test.ts
+++ b/test/basic.test.ts
@@ -83,6 +83,8 @@ describe('pages', () => {
expect(html).toContain('Composable | star: auto imported from ~/composables/nested/bar.ts via star export')
// should import components
expect(html).toContain('This is a custom component with a named export.')
+ // should remove dev-only and replace with any fallback content
+ expect(html).toContain('Some prod-only info')
// should apply attributes to client-only components
expect(html).toContain('')
// should render server-only components
diff --git a/test/fixtures/basic/pages/index.vue b/test/fixtures/basic/pages/index.vue
index 7b6c4bb7349d..2b31da638015 100644
--- a/test/fixtures/basic/pages/index.vue
+++ b/test/fixtures/basic/pages/index.vue
@@ -11,6 +11,14 @@
Composable | star: {{ useNestedBar() }}
Some dev-only info
Some dev-only info
+
+
+ Some dev-only info
+
+ Some prod-only info
+
+
+
Path: {{ $route.fullPath }}
Link
From a23a75fc97d207a6dcea1c62666b9319ba25a9d4 Mon Sep 17 00:00:00 2001
From: Inesh Bose <2504266b@student.gla.ac.uk>
Date: Fri, 12 May 2023 17:44:09 +0100
Subject: [PATCH 2/3] fix: tests
---
test/basic.test.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/basic.test.ts b/test/basic.test.ts
index 322437db161c..cee3345af9f0 100644
--- a/test/basic.test.ts
+++ b/test/basic.test.ts
@@ -84,7 +84,7 @@ describe('pages', () => {
// should import components
expect(html).toContain('This is a custom component with a named export.')
// should remove dev-only and replace with any fallback content
- expect(html).toContain('Some prod-only info')
+ expect(html).toContain(isDev() ? 'Some dev-only info' : 'Some prod-only info')
// should apply attributes to client-only components
expect(html).toContain('')
// should render server-only components
From 5f9b25ae0ad2afcd030c8881eb027867e7894d69 Mon Sep 17 00:00:00 2001
From: Daniel Roe
Date: Sat, 13 May 2023 22:50:17 +0100
Subject: [PATCH 3/3] fix: invoke slot
---
packages/nuxt/src/app/components/dev-only.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/nuxt/src/app/components/dev-only.ts b/packages/nuxt/src/app/components/dev-only.ts
index 3c88ccae2cf5..914ba6f6e445 100644
--- a/packages/nuxt/src/app/components/dev-only.ts
+++ b/packages/nuxt/src/app/components/dev-only.ts
@@ -6,6 +6,6 @@ export default defineComponent({
if (process.dev) {
return () => props.slots.default?.()
}
- return () => props.slots.fallback
+ return () => props.slots.fallback?.()
}
})