Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
/frameworkPublic archive

feat(components): .client.vue / .server.vue convention - #1919

Closed
antfu wants to merge 33 commits into
mainfrom
feat/client-server-components
Closed

feat(components): .client.vue / .server.vue convention#1919
antfu wants to merge 33 commits into
mainfrom
feat/client-server-components

Conversation

@antfu

@antfuantfu commented Nov 15, 2021

Copy link
Copy Markdown
Member

🔗 Linked issue

nuxt/nuxt#11884

Continues from #1853

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR bring .client.vue and .server.vue conversion for components directly. This PR is focus on .client.vue client only components with optional .server.vue as SSR fallback. Server-only components will be left to future PRs.

How it works

When we do the component scanning, components with suffixes will be treated as one component entry with two file paths. Then we create a virtual component using templates with the wrapper by <ClientOnly>. This way we could use the component as normal but be able to do environment-specific logic.

Progress
  • Scanning for .server.vue and .client.vue
  • Virutal component
  • Optimize bundling

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify

netlifyBot commented Nov 15, 2021

Copy link
Copy Markdown

✔️ Deploy Preview for nuxt3-docs canceled.

🔨 Explore the source changes: 399f944

🔍 Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/6232552869a46b0008f21714

Comment threadpackages/kit/src/types/components.ts
Comment threadpackages/nuxt3/src/components/module.ts Outdated
Comment threadpackages/nuxt3/src/components/templates.ts Outdated
@antfuantfu changed the title feat: client-server only componentsfeat(components): .client.vue / .server.vue conventionNov 15, 2021
@pi0

pi0 commented Nov 17, 2021

Copy link
Copy Markdown
Member

Hi @antfu do you mind to fix merge conflicts?

@antfu

antfu commented Nov 18, 2021

Copy link
Copy Markdown
MemberAuthor

For the bundle optimization, for now, I can see two ways of doing it:

  • We create two "virtual components" that and generate two components plugin templates for client / server
  • We create a stub virtual component and add two transform plugins for server/client to transform the stub into env-specific components

Do you have any idea on them? Thanks

@pi0

pi0 commented Nov 22, 2021

Copy link
Copy Markdown
Member

Some improvement suggestions:

  • We can simplify component interface with path: { [env: 'client' | 'server' | 'default']: string }
  • Instead of always using a virtual component wrapping with <ClientOnly>, we can configure aliases for server/client bundlers differently that resolves to env specific version (unless there is missing pair of component for env)

@antfu

antfu commented Dec 2, 2021

Copy link
Copy Markdown
MemberAuthor

We can simplify component interface with path: { [env: 'client' | 'server' | 'default']: string }

My initial idea is that filePath could serve the path virtual module so the rest of the code could remove as-is. Also it would be easier to check if a component has multiple versions by if(component.envPaths). This interface you proposal could also do, but is that ok as I guess it will be a breaking change?

Instead of always using a virtual component wrapping with , we can configure aliases for server/client bundlers differently that resolves to env specific version (unless there is missing pair of component for env)

I'd love to, but I guess that's more like the initial approach that we faced the hydration errors - and that's why we introduced the <ClientOnly> component. I have given another try based on the work of this PR on branch https://github.com/nuxt/framework/tree/feat/client-server-components-redirects , but unfortunately, the hydration does not seem to like it.

image

@antfu

antfu commented Dec 2, 2021

Copy link
Copy Markdown
MemberAuthor

Guess what, I made it work! 🚀d093fa9 - Pushed to this branch

@antfu
antfu marked this pull request as ready for review December 2, 2021 06:23
@andysay

Copy link
Copy Markdown

hello, when it will be merged??

Comment threadpackages/nuxt3/src/app/components/client-only.mjs Outdated
@danielroedanielroe added components enhancement New feature or request nuxt3 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing labels Jan 21, 2022
@antfu
antfu marked this pull request as draft March 10, 2022 04:57
@antfu

antfu commented Mar 10, 2022

Copy link
Copy Markdown
MemberAuthor

Marked as draft

Global mode probably won't work due to the latest refactor of how components been resolved. Working with @danielroe on this.

@antfu

Copy link
Copy Markdown
MemberAuthor

Resolved :)

@antfu
antfu marked this pull request as ready for review March 10, 2022 09:56
Diizzayy added a commit to Diizzayy/framework that referenced this pull request Mar 28, 2022
@atinux

Copy link
Copy Markdown
Member

New conflicts again 😅

What do we do about this PR? If agree, I think next step if to update the docs in https://v3.nuxtjs.org/docs/directory-structure/components#clientonly-component in order to merge.

@pi0

pi0 commented Mar 31, 2022

Copy link
Copy Markdown
Member

I think will finally have to rework this PR. Idea is nice but implementation needs to be revised with simpler component options.

@pi0

pi0 commented Apr 15, 2022

Copy link
Copy Markdown
Member

Thank you again @antfu for working on this. Since PR is stalled with conflicts and I expect a simpler interface for implementation, let's track this via nuxt/nuxt#11884. We are also closer with nitro to support server-only components 🤞🏼

@pi0pi0 closed this Apr 15, 2022
@pi0
pi0 deleted the feat/client-server-components branch April 15, 2022 08:04
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3.xcomponentsenhancementNew feature or requestnuxt3🍰 p2-nice-to-havePriority 2: nothing is broken but it's worth addressing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@antfu@pi0@andysay@atinux@WoH@danielroe