Skip to content

fix: set default render when template is empty #1745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 4 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ export default function loader(
}

// template
let templateImport = ``
let templateRequest
const renderFnName = isServer ? `ssrRender` : `render`
const renderReplace = `script.${renderFnName} = ${renderFnName}`
let templateImport = `const ${renderFnName} = () => {}`
let templateRequest
if (descriptor.template) {
const src = descriptor.template.src || resourcePath
const idQuery = `&id=${id}`
Expand Down Expand Up @@ -197,12 +198,7 @@ export default function loader(
})
}

let code = [
templateImport,
scriptImport,
stylesCode,
templateImport ? `script.${renderFnName} = ${renderFnName}` : ``,
]
let code = [templateImport, scriptImport, stylesCode, renderReplace]
.filter(Boolean)
.join('\n')

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/template-empty.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template></template>
21 changes: 21 additions & 0 deletions test/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,24 @@ test('postLoaders support', async () => {
// class="red" -> class="green"
expect(instance.$el.className).toBe('green')
})

test('empty template', async () => {
const { componentModule } = await mockBundleAndRun({
entry: 'template-empty.vue',
})

expect(componentModule.render).not.toBeUndefined()
expect(componentModule.render()).toBeUndefined()
expect(componentModule.ssrRender).toBeUndefined()
})

test('empty template with ssr', async () => {
const { componentModule } = await mockBundleAndRun({
entry: 'template-empty.vue',
target: 'node',
})

expect(componentModule.ssrRender).not.toBeUndefined()
expect(componentModule.ssrRender()).toBeUndefined()
expect(componentModule.render).toBeUndefined()
})