Войдите или зарегистрируйтесь
Вы сможете писать комментарии и посты, ставить лайки и другое
Поиск
Тёмная тема

How to use Quill Editor with Nuxt 3 and SSR (Vue)

If you try to use Quill Editor with Nuxt 3 when rendering a page in SSR you will get this error:
500 document is not defined.
That means NodeJS doesn't have the global variable 'document'. Because SSR rendering is executed in
a NodeJS environment, not a browser.

The sad fact: <client-only> won't help with this problem. The problem with quill's code is that during import, it assumes it's being executed in the browser. I hope you remember that the code imported from the module is not just imported, but executed, i.e. the authors of Quill wrote it so that the 'document' object is immediately accessed there. Very bad.

One solution is to disable SSR, but its an awful solution. But the second solution is to use dynamic JS imports.

My <script lang="ts" setup> in QuillEditor.vue in Nuxt 3 project:
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
// import Quill from 'quill'; // SSR problem with 'document', need to use dynamic import
import type Quill from 'quill';

const elemForQuillEditor = ref<HTMLDivElement|null>(null);

let editor: null|Quill = null; // Do not store in ref() - it causes bugs!

// ...

async function createQuillAndSetListeners() {
  const Quill = (await import('quill')).default; // This is most important thing - usage of JS dynamic import

  if (!elemForQuillEditor.value) return;
  editor = new Quill(elemForQuillEditor.value, {
    theme: 'snow',
    modules: {
      history: {
        delay: 2000,
        maxStack: 500,
        userOnly: true,
      },
      toolbar: {
        container: [
          ['bold', 'italic', 'underline', 'strike'],
          ['link'],
          [{ list: 'ordered' }, { list: 'bullet' }],
          [{ script: 'sub' }, { script: 'super' }],
          [{ header: [1, 2, 3, 4, 5, 6, false] }],
          [{ color: [] }, { background: [] }],
          ['clean'],
          ['undo', 'redo'],
        ],
        handlers: {
          undo() {
            editor?.history.undo();
          },
          redo() {
            editor?.history.redo();
          },
        },
      },
    },
    placeholder: props.placeholder,
  });
  
  editor.on('text-change', () => {
    if (!editor) return;
    // ... my other code
  });
}

// ...

onMounted(createQuillAndSetListeners);

Now your Quill editor will work in Nuxt 3 even during SSR!
+2
90

Vue.js popularity in 2024

Let's try to measure the popularity of Vue.JS. I really like this framework and I am a supporter of its popularization.

First, let's look at the download statistics on NPM.
Now vs year ago:
vue - 4,868,119 - 3,746,361
@angular/core - 3,416,382 - 3,015,855
react - 23,763,131 - 20,548,838

As you can see, React is in the first place in absolute values. And VueJS is only in second place.

And now let's look at the percentage growth relative to last year's values.
vue +29,9%
angular +13,3%
react +15,6%
Hurray! Vue's popularity is growing faster than any of the three!
And now let's go through the sites from the top of Google and see what JS frameworks are used there.

For example, let's take the search query "rent car".
To understand which libraries each site uses, I used Wappalyzer browser extension.
Websites from search results; NF means "there is no framework from the big three".
rentalcars.com - NF
enterprise.com - NF
kayak.com - React
avis.com - NF (old AngularJS)
localrent.com - Vue
hertz.com - NF (old BackboneJS)
sixt.com - React
budget.com - NF (old AngularJS)
zipcar.com - NF
turo.com - React
autoeurope.eu - NF
alamo.com - React
rent.toyota.co.jp - NF
booking.com - React
costcotravel.com - React
borent.nl - NF
europcar.com - Vue
turo.com - React
vipcars.com - NF
skyscanner.net - React
tripadvisor.com - NF
timescar-rental.com - NF
klook.com - Vue
wiberrentacar.com - Vue
uber.com - NF
dollar.com - React
edreams.com - Vue
nationalcar.com - NF
thrifty.com - NF

As you can see, Vue is actively moving forward!
Показать полностью...
+2
38

The Same Typeface in Woody Allen's Films

In his films, Woody Allen consistently uses the same typeface in the opening and closing credits. Midnight in Paris (2011):
Показать полностью...
+2
10

Quentin Tarantino and his foot fetish: a complete list of all his films featuring scenes with feet and legs - photos and videos

Fans of Quentin Tarantino know that he has a foot fetish. For those unfamiliar with the term: it's when a man has a particular fascination with women's legs, and even more so with their feet. It's safe to say that Quentin Tarantino is the most famous foot fetishist in the world.

Let's start with Quentin Tarantino's first real film - Reservoir Dogs (1992). I'm skipping "My Best Friend's Birthday", as it was never officially released.
There's nothing related to foot fetishism in Reservoir Dogs: the film features only tough men. Women appear only briefly in a few background scenes. I found just one scene where a woman is shown in the foreground - the carjacking moment.
Показать полностью...
+3
15