nuxt-stencil icon indicating copy to clipboard operation
nuxt-stencil copied to clipboard

Can be used in production?

Open patrickalima98 opened this issue 6 years ago • 16 comments

Hello @Gomah , this project can be used in production?

patrickalima98 avatar Oct 18 '19 21:10 patrickalima98

Hey @patrickalima98, using the spa mode in your nuxt.config.js, yes, it's ready for production.

However, for universal & generate mode, Vue’s throwing few errors when hydrating on CSR, it's probably due to the comments that the stencil renderer injects when rendering stencil components. I'll investigate more.

Gomah avatar Oct 19 '19 07:10 Gomah

Hello @Gomah , i'm currently working on a components library built with Stencil and my Website is are built with Nuxt, I'II investigate also.

Thank you :)

patrickalima98 avatar Oct 19 '19 13:10 patrickalima98

So after further investigation, I assume the issue is with the Vue client-side hydration:

I first thought the comments injected were causing the issue:

(elm ssr, vnode.text is CSR)

Screen Shot 2019-10-23 at 12 29 39 pm

But even by removing those comments using a RegExp before returning the html to the DOM, I could see the issue persisting:

Screen Shot 2019-10-23 at 12 32 18 pm

I think those nodes mismatch because the defineCustomElements function is called after the Vue hydration.

On the assertNodeMatch:

SSR:

<bm-button color="is-primary" class="hydrated" s-id="1">
  <button class="button is-primary" c-id="1.0.0.0">
    <!--s.1.1.1.0.--><!--t.0.1--> Click Me! 
  </button>
</bm-button>

CSR, before vue hydration:

<bm-button color="is-primary" class="hydrated" s-id="1">
  Click Me!
</bm-button>

After vue & stencil hydration:

<bm-button color="is-primary" class="hydrated">
<!---->
  <button class="button is-primary hydrated">
    Click Me!
  </button>
</bm-button>

Not sure where to go from there, maybe defineCustomElements needs to be called and hydrate the stencil components before the Vue hydration, I need to investigate further.

Gomah avatar Oct 23 '19 01:10 Gomah

Hi @Gomah, i can't understand the erros rss, i created a new project with Nuxt and added your plugin, after this, I included my library built in Stencil and works fine for me, please look my screenshots.

image

image

My prompt:

image

My console:

image

I'm using the hydrate folder with loader folder.

patrickalima98 avatar Oct 23 '19 12:10 patrickalima98

@patrickalima98 What's your stencil configuration in the nuxt.config.js file?

Gomah avatar Oct 23 '19 23:10 Gomah

And yeah, it will visually work fine but the DOM will be re-rendered as there are mismatching nodes.

Gomah avatar Oct 23 '19 23:10 Gomah

@Gomah this is my nuxt.config.js

const path = require('path');
export default {
  mode: 'universal',
  /*
  ** Headers of the page
  */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },
  /*
  ** Global CSS
  */
  css: [
    '@nuiverse/core/dist/nuiverse-ui/nuiverse-ui.css'
  ],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
  ],
  /*
  ** Nuxt.js dev-modules
  */
  buildModules: ['@nuxt/typescript-build', 'nuxt-stencil'],
  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    ['nuxt-i18n', {
      locales: [
        {
          code: 'pt-br',
          file: 'pt-BR.js'
        },
      ],
      lazy: true,
      langDir: 'lang/',
      strategy: 'prefix_and_default',
      defaultLocale: 'pt-br',
      // Enable browser language detection to automatically redirect user
      // to their preferred language as they visit your app for the first time
      // Set to false to disable
      detectBrowserLanguage: {
        // If enabled, a cookie is set once a user has been redirected to his
        // preferred language to prevent subsequent redirections
        // Set to false to redirect every time
        useCookie: true,
        // Cookie name
        cookieKey: 'i18n_redirected',
        // Set to always redirect to value stored in the cookie, not just once
        alwaysRedirect: true,
        // If no locale for the browsers locale is a match, use this one as a fallback
        fallbackLocale: null
      },
    }],
  ],
  /*
  ** Axios module configuration
  ** See https://axios.nuxtjs.org/options
  */
  axios: {
  },
  /*
  ** Build configuration
  */
  build: {
    /*
    ** You can extend webpack config here
    */
    extend (config, ctx) {
      config.module.rules.push(
        {
            test: /\.md$/,
            include: path.resolve(__dirname, "content"),
            loader: "frontmatter-markdown-loader",
        }
      );
    },
    babel: {
      plugins: [
        ["@babel/plugin-proposal-decorators", { legacy: true }],
        ["@babel/plugin-proposal-class-properties", { loose: true }]
      ]
    }
  },
  stencil: {
    /**
     * Required options
     */

    // Your library name, or the path to its root folder.
    lib: 'E:/Projetos/Nuinalp/nfw/website/node_modules/@nuiverse/core',

    // The prefix to whitelist
    prefix: 'nv-',

    // By default, it takes the lib name. e.g: bulmil/dist/hydrate
    hydratePath: 'E:/Projetos/Nuinalp/nfw/website/node_modules/@nuiverse/core/hydrate',

    // By default, it takes the lib name. e.g: bulmil/dist/loader
    loaderPath: 'E:/Projetos/Nuinalp/nfw/website/node_modules/@nuiverse/core/loader',
  },
}

patrickalima98 avatar Oct 23 '19 23:10 patrickalima98

Potentially a Stencil issue, see https://github.com/ionic-team/stencil/issues/2068

Gomah avatar Dec 11 '19 08:12 Gomah

Yes @Gomah, I can see.

patrickalima98 avatar Dec 11 '19 12:12 patrickalima98

Hello, I'm considering to use nuxt+stencil in the near future, with nuxt in generate mode. Now that the issue with stencil is fixed, does vue still throw errors when hydrating on CSR? If you could test and report... thanks!

paolodina avatar Mar 15 '20 23:03 paolodina

Hey @paolodina, sorry for the late reply.

I'll be jumping back to Stencil + Nuxt in May so I'll have time to have a look at it again!

Gomah avatar Apr 29 '20 04:04 Gomah

Hello @Gomah, How are you? Any news about the project?

patrickalima98 avatar Oct 07 '20 14:10 patrickalima98

Hey @patrickalima98, the project is on pause at the moment, will probably continue work on this module once Nuxt 3 is released!

Gomah avatar Oct 07 '20 22:10 Gomah

Hello @Gomah, i'm very excited to it :)

patrickalima98 avatar Oct 18 '20 02:10 patrickalima98

@Gomah Nuxt 3 is out ;) I can't find any information about how to use stencil / webcomponents in nuxt. Are you aiming to fix that problem?

DirkWolthuis avatar Oct 13 '21 13:10 DirkWolthuis

Hello @Gomah , thanks for an awesome package. I have a question. Is possible on nuxt.config.js assign more than one stencil project? I have 2 stencil projects that I want to implement

Thank you

billsur avatar Feb 09 '22 12:02 billsur