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.

"Warning: Prop `data-offset-key` did not match" (React, Next, webpack-hmr)

See original GitHub issue

I’ve just upgraded from Slate version 0.19.20 to 0.32.0. All the new changes seem like improvements (bravo!). But, there’s a new behavior that’s completely blocking my development. I’ve spent hours to trying solutions but am out of ideas. I’d love your suggestions / solutions.

I use React and the Next.js framework, which uses webpack-hmr (“Hot Module Replacement”) to auto-update the browser when server-side or client-side dev code changes. This is invaluable for development.

I tried Slate’s Checklist example with React 16.2 and Next 4.2.1. The first time the example renders when the server starts, the Slate example works fine. When I refresh the browser, or when code changes which auto-updates the browser, there’s an error in the browser console (presumably from React):

Warning: Prop data-offset-key did not match. Server: “6:0” Client: “3:0”

Each time I refresh without doing anything else, the Server version in the warning goes up by 3:

Warning: Prop data-offset-key did not match. Server: “9:0” Client: “3:0” Warning: Prop data-offset-key did not match. Server: “12:0” Client: “3:0” etc.

After that first refresh, Slate breaks. The Value.selection doesn’t change despite moving the cursor. Typed characters appear at the beginning of the text even though the cursor is elsewhere. I have to manually restart the server to get it working again. This makes development so painful I’d rather switch to a different editor library rather than make development this painful. Slate is a core part of what we’re building. I also worry that this behavior might fail in production, but I haven’t tried it.

Is there anything in the way data-offset-key is used in the code that could cause this problem? I looked at the Slate code where data-offset-key is mentioned, but I didn’t get anywhere.

Any ideas?

It’s some work, but if it will help, and if you’ll engage with this issue, I’ll create a dummy project with this problem for you to run.

gif: http://recordit.co/06btFHGuwj OS is macOS 10.13.2 Browser is Chrome Version 63.0.3239.84 (Official Build) (64-bit)

Issue Analytics

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

github_iconTop GitHub Comments

14reactions
taro-piecewisecommented, Jan 31, 2018

Future readers: I had a problem very similar, if not identical, to the above and solved it by calling resetKeyGenerator() before the first Value.fromJSON({…}) call I made.

Note: Your first call to Value.fromJSON({…}) may perhaps be outside any of your classes/components as it is in a few of the walkthroughs in the docs, e.g. ‘Installing Slate’.

5reactions
tashburncommented, Jan 8, 2018

@ianstormtaylor, thanks for the prompt response and solution. I was already using resetKeyGenerator with the old version of Slate, but I was running it once when the server started. I forgot about it, and it was working fine.

Now, when I run resetKeyGenerator in the constructor of my outermost react component, that eliminates the problem. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-select: How do I resolve “Warning: Prop `id` did not match”
try to add prop instanceId set as unique string and should work.
Read more >
react-hydration-error - Next.js
When css-in-js libraries are not set up for pre-rendering (SSR/SSG) it will often lead to a hydration mismatch. In general this means the...
Read more >
Webpack's HMR & React-Hot-Loader — The Missing Manual
js from a different directory that doesn't match publicPath settings (you'll have to setup ANOTHER proxy on the Express server that's running on ......
Read more >
Frequently Asked Questions - Material UI - MUI
Prop className did not match. There is a class name mismatch between the client and the server. It might work for the first...
Read more >
Optimizing Performance - React
props.words will compare as equal, even though the actual words in the array have changed. The ListOfWords will thus not update even though...
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