Code Monkey home page Code Monkey logo

Comments (11)

Fabioni avatar Fabioni commented on June 10, 2024 3

Same here. I am only using nuxt-2

from nuxt-delay-hydration.

harlan-zw avatar harlan-zw commented on June 10, 2024 2

Thanks for the idea. This is available with v1 of the module, which only supports Nuxt v3. I won't be porting it back to the v0 version.

// nuxt.config.ts
export default {
  delayHydration: {
    include: [
      '/**',
    ],
    exclude: [
      '/admin/**'
    ],
  },
}

from nuxt-delay-hydration.

harlan-zw avatar harlan-zw commented on June 10, 2024 2

Thanks for letting me know, I chose not to include this for Nuxt v2 due to the effort involved.

I've re-opened the issue as I may re-consider it, but at this stage, I have other priorities to work on sorry.

from nuxt-delay-hydration.

oppianmatt avatar oppianmatt commented on June 10, 2024 1

I found a solution, I've got a build module that rewrites the js (like the author has done with nuxt) and I replace this part

    const replace = `
      const hydrationEvent = window.location.pathname.match(${URLS_TO_SKIP}) ?
        false :
        await delayHydration()
    `

    template.replace('const hydrationEvent = await delayHydration()', replace)

where URLS_TO_SKIP is a regex of URLs I would like to bypass delay hydration

but this could be added to the original module and made a setting

from nuxt-delay-hydration.

harlan-zw avatar harlan-zw commented on June 10, 2024

Hey @Fabioni

This is a good idea if there are only certain pages you need to run with init or mount mode.

Could you confirm if manual mode and DelayHydration component can't be used to achieve what you want though?

from nuxt-delay-hydration.

harlan-zw avatar harlan-zw commented on June 10, 2024

Going to close this off as there's been no reply. Feel free to re-open if the above doesn't apply and you would still like the feature

from nuxt-delay-hydration.

oppianmatt avatar oppianmatt commented on June 10, 2024

I too am interested in this but manual mode doesn't cut it as the nuxt app is mounted and plugins fire increasing blocking time.

Perhaps the inject hydrate API can be put on the component, and then in beforeCreate on the component it could call hydrate now on the pages we would want to hydrate straight away (like heavy UI js pages that aren't for SEO)

from nuxt-delay-hydration.

danmindru avatar danmindru commented on June 10, 2024

darn, too bad it's only for nuxt 3. Was just looking for this in v0. 💔

from nuxt-delay-hydration.

Fabioni avatar Fabioni commented on June 10, 2024

Thanks for letting me know, I chose not to include this for Nuxt v2 due to the effort involved.

I've re-opened the issue as I may re-consider it, but at this stage, I have other priorities to work on sorry.

Thanks @harlan-zw for reopening this issue. I will really appreciate if you find the time to do that. Unfortunately I can only use your plugin once this feature exist.

from nuxt-delay-hydration.

junkym0nk3y avatar junkym0nk3y commented on June 10, 2024

oppianmatt
Thanks for clue.

I made (with my colleague) a new module, that works in mount mode

import fs from 'fs';

export default function nuxtDelayHydrationExclude(config) {
    const excludePaths = config.excludePaths;
    const URLS_TO_SKIP = new RegExp(`^(${excludePaths.join('|')})(\\/|$)|(^|\\/+)(${excludePaths.join('|')})(\\/|$)`);

    this.nuxt.hook('build:templates', ({
        templatesFiles,
    }) => {
        const clientTemplate = templatesFiles.find(t => t.dst === 'client.js');

        if (clientTemplate) {
            const fileContent = fs.readFileSync(clientTemplate.src, {encoding: 'utf-8'});
            const replace = `
                const delayDisabled = window.location.pathname.match(${URLS_TO_SKIP})
                delayDisabled ?
                    false :
                    await delayHydration()
                console.warn('delay-hydration is:', delayDisabled ? 'disabled' : 'enabled')
            `;

            const regex = /(?<!const\s+hydrationEvent\s+=\s+)(await\s+delayHydration\(\))/g;
            const modifiedContent = fileContent.replace(regex, replace);
            fs.writeFileSync(clientTemplate.src, modifiedContent, 'utf-8');
        }
    });
}

If it is needed for someone, just add it right after 'nuxt-delay-hydration' in modules section:

modules: [
    'nuxt-delay-hydration',
    // excludePaths – will includes all subpages
    ['~/config/modules/nuxtDelayHydrationExclude', {excludePaths: ['/page1', '/page2']}],
],

from nuxt-delay-hydration.

harlan-zw avatar harlan-zw commented on June 10, 2024

The Nuxt 2 module is deprecated and won't receive any new updates from here on out, sorry.

Feel free to use the above work around though.

from nuxt-delay-hydration.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.