question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CharacterCount not working when multiples editor instances live in the same page

See original GitHub issue

What’s the bug you are facing?

@tiptap/extension-character-count not working when two or more editors instances live in the same page.

  • The first editor instance does not update unless the second editor instance updates
  • When the first editor instance update char count, it updates using the char count of the second editor instance

How can we reproduce the bug on our side?

  1. Create an editor using https://tiptap.dev/api/extensions/character-count extension, remember to display the char count using editor.storage.characterCount.characters()
  2. Invoke two instances of the previously created editor on the same page
  3. Update each editor content

Can you provide a CodeSandbox?

https://codesandbox.io/s/lively-glade-8h4rc8?file=/src/App.js

What did you expect to happen?

Each editor instance should update char count separately

Anything to add? (optional)

Nope

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bdbchcommented, Apr 9, 2022

So the reason why having multiple contexts without using .configure is not working right now is because of the way the extensions are created. Right now, when you write your own extension you need to write something like this:

import { Extension } from '@tiptap/core';
const MyAwesomeExtension = Extension.create();

The important thing here is, that we are not creating a new instance here but create one global instance of the extension right at the point where the extension is created.

In Extension.ts line 318 we can see, that Extension.create is doing the following:

static create<O = any, S = any>(config: Partial<ExtensionConfig<O, S>> = {}) {
  return new Extension<O, S>(config)
}

That means we will always have one object instanced from this Extension class for every editor. The Extension.configure function is calling Extension.extend which will create a new child extension everytime it’s called which is why it’s working fine when .configure is used.

I referenced this in a new ticket #2694.

@obetomuniz @cooliopas I hope for now my temporary solution works fine!

0reactions
stale[bot]commented, Jul 6, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make show a character counter for several textareas in ...
You need to do querySelectorAll on all the inputs and then attach a oninput event listener, like this: var textareas = document.
Read more >
Word Count & Char Count Plugin | CKEditor.com
WordCount Plugin for CKEditor that counts the words an shows the word count in the footer of the editor. DEMO Page. License.
Read more >
How to count characters in Excel cell and range - Ablebits
Want to know how many characters there are in a certain cell? This tutorial will help you choose an Excel formula for character...
Read more >
Video: Work with word counts in your document
To see the number of words in your document, look at the status bar at the lower left bottom of the Word window....
Read more >
Show word count - Microsoft Support
Word counts the number of words in a document while you type. Word also counts pages, paragraphs, lines, and characters. Windows macOSWeb.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found