Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.4.1] Code in CodeEditor isn't updated #369

Open
thomasdax98 opened this issue Sep 7, 2023 · 0 comments
Open

[2.4.1] Code in CodeEditor isn't updated #369

thomasdax98 opened this issue Sep 7, 2023 · 0 comments

Comments

@thomasdax98
Copy link

thomasdax98 commented Sep 7, 2023

Issue

If the code passed to <LiveProvider> changes, the <CodeEditor> isn't updated. This occurs in v2.4.1 of react-live.

Demo

CodeSandbox: https://codesandbox.io/s/react-live-code-update-issue-w2lxsg?file=/src/App.js

After two seconds the code passed to the <LiveProvider> changes from abc to def. This change is reflected in the <LivePreview> but not in the <CodeEditor>.

Reason

The reason is the following code:

https://github.com/FormidableLabs/react-live/blob/v2.4.1/src/components/Editor/index.js#L13-L15

if (state.prevCodeProp && props.code !== state.prevCodeProp) {
  setState({ code: props.code, prevCodeProp: props.code });
}

In the if(), you check if state.prevCodeProp is defined. However, this can never be true because it's never initialized. The bug was introduced in v2.3.0. Previously, the code read:

https://github.com/FormidableLabs/react-live/blob/v2.2.3/src/components/Editor/index.js#L18-L20

if (props.code !== state.prevCodeProp) {
  return { code: props.code, prevCodeProp: props.code };
}

That worked as expected.

Fix

I already pushed a fix to my fork of your repo: thomasdax98@d977799

However, I don't know how I can merge it to your repo since there is no v2 branch. Could you help me with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant