Skip to content

Commit

Permalink
refactor(nuxt): don't wrap server placeholders/client fallbacks (#21980)
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-julien committed Sep 13, 2023
1 parent 084b2b0 commit 95d1f99
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/nuxt/src/components/loader.ts
Expand Up @@ -48,7 +48,7 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
let identifier = map.get(component) || `__nuxt_component_${num++}`
map.set(component, identifier)

const isServerOnly = component.mode === 'server' &&
const isServerOnly = !component._raw && component.mode === 'server' &&
!components.some(c => c.pascalName === component.pascalName && c.mode === 'client')
if (isServerOnly) {
imports.add(genImport(serverComponentRuntime, [{ name: 'createServerComponent' }]))
Expand All @@ -59,7 +59,7 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
return identifier
}

const isClientOnly = component.mode === 'client' && component.pascalName !== 'NuxtClientFallback'
const isClientOnly = !component._raw && component.mode === 'client'
if (isClientOnly) {
imports.add(genImport('#app/components/client-only', [{ name: 'createClientOnly' }]))
identifier += '_client'
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt/src/components/module.ts
Expand Up @@ -170,6 +170,7 @@ export default defineNuxtModule<ComponentsOptions>({
if (component.mode === 'client' && !newComponents.some(c => c.pascalName === component.pascalName && c.mode === 'server')) {
newComponents.push({
...component,
_raw: true,
mode: 'server',
filePath: resolve(distDir, 'app/components/server-placeholder'),
chunkName: 'components/' + component.kebabName
Expand Down
2 changes: 2 additions & 0 deletions packages/nuxt/src/core/nuxt.ts
Expand Up @@ -265,13 +265,15 @@ async function initNuxt (nuxt: Nuxt) {
if (nuxt.options.experimental.clientFallback) {
addComponent({
name: 'NuxtClientFallback',
_raw: true,
priority: 10, // built-in that we do not expect the user to override
filePath: resolve(nuxt.options.appDir, 'components/client-fallback.client'),
mode: 'client'
})

addComponent({
name: 'NuxtClientFallback',
_raw: true,
priority: 10, // built-in that we do not expect the user to override
filePath: resolve(nuxt.options.appDir, 'components/client-fallback.server'),
mode: 'server'
Expand Down
7 changes: 7 additions & 0 deletions packages/schema/src/types/components.ts
Expand Up @@ -16,6 +16,13 @@ export interface Component {
* components will be used instead of lower priority components.
*/
priority?: number
/**
* Allow bypassing client/server transforms for internal Nuxt components like
* ServerPlaceholder and NuxtClientFallback.
*
* @internal
*/
_raw?: boolean
}

export interface ScanDir {
Expand Down

0 comments on commit 95d1f99

Please sign in to comment.