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

fix: dynamically reconfigure codemirror instead of recreate on rerender #1125

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

danieldelcore
Copy link
Contributor

@danieldelcore danieldelcore commented Apr 25, 2024

Closes: #1124

This PR separates codemirror instantiation logic from subsequent prop updates.

Previously every time a decorator or other dependency is updated, it would trigger a complete recreation of the sandpack instance, resulting in strange behaviour such as the cursor would be repositioned or elements would flash.

To fix this, I've moved all extension configuration into a seperate hook, when rerun will recreate the entire config and dispatch a codemirror reconfigure message which safely updates the instance without any side effects.

I have added a storybook example which illustrates the behaviour.

Copy link

codesandbox bot commented Apr 25, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Apr 25, 2024

@danieldelcore is attempting to deploy a commit to the CodeSandbox Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codesandbox-ci bot commented Apr 25, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@danieldelcore danieldelcore changed the title Decorator updates Dynamically reconfigure codemirror instead of recreate on rerender Apr 26, 2024
@danieldelcore danieldelcore changed the title Dynamically reconfigure codemirror instead of recreate on rerender fix: dynamically reconfigure codemirror instead of recreate on rerender Apr 26, 2024
@danieldelcore
Copy link
Contributor Author

cc: @CompuIves / @danilowoz would really appreciate your 👁️ 👁️ on this one if you have some time 🙏

Copy link

vercel bot commented Apr 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sandpack-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2024 8:59am

Copy link
Member

@danilowoz danilowoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense! Thank you

@danilowoz danilowoz merged commit a41d1a0 into codesandbox:main Apr 26, 2024
7 of 13 checks passed
@danieldelcore
Copy link
Contributor Author

Legend! Thanks so much!

@danilowoz
Copy link
Member

danilowoz commented Apr 26, 2024

It seems that something went wrong with the production build: https://sandpack.codesandbox.io/docs/quickstart
Screenshot 2024-04-26 at 13 49 54

I will investigate it soon

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

Successfully merging this pull request may close these issues.

Changing decorators recreates Codemirror
2 participants