You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
I have read the documentation and cannot find an answer.
Describe the bug
When I initialize the MDXEditor with the imagePlugin enabled and content containing an image reference with a URL that contains an ampersand, I get an unwanted change event on the first render without the user interacting with the editor at all.
Here is a code snippet that helps to discuss the problem I am seeing:
Content passed in to the editor: ![test-image](https://test.blob.net/foo/bar/1234/attachments/Screenshot.png?q1=foo&q2=bar)
Content logged in the unwanted change event: ![test-image](https://test.blob.net/foo/bar/1234/attachments/Screenshot.png?q1=foo\&q2=bar)
The only difference I am able to spot is the backslash before the ampersand. It seems that the plugin escapes the ampersand which in turn triggers a change event.
If I pass in this content instead, onChange is not called: ![test-image](https://test.blob.net/foo/bar/1234/attachments/Screenshot.png?q1=foo\\&q2=bar)
Notice the double backslash before the ampersand.
This also seems to do the trick: ![test-image](https://test.blob.net/foo/bar/1234/attachments/Screenshot.png?q1=foo&q2=bar)
Reproduction
Here is a codesandbox that reproduces the behaviour described above. As you can see in the console, the onChange is triggered after the first render without any interaction from the user or external changes to the markdown string. https://codesandbox.io/p/devbox/suspicious-breeze-x8sfzs
Expected behavior
I expect the onChange not to be called unless the user actually makes changes to the content.
If escaping the URLs are necessary for it to be valid markdown, is there a helper method I could call instead to do the escaping of the content before passing it to the editor so that I can prevent the unwanted change event?
Another alternative would be to throw an error if the markdown passed to the editor is not valid markdown instead of converting it automatically and firing a callback. The this type of behaviour would be easier to spot and debug.
The text was updated successfully, but these errors were encountered:
Describe the bug
When I initialize the
MDXEditor
with theimagePlugin
enabled and content containing an image reference with a URL that contains an ampersand, I get an unwanted change event on the first render without the user interacting with the editor at all.Here is a code snippet that helps to discuss the problem I am seeing:
Content passed in to the editor:
![test-image](https://test.blob.net/foo/bar/1234/attachments/Screenshot.png?q1=foo&q2=bar)
Content logged in the unwanted change event:
![test-image](https://test.blob.net/foo/bar/1234/attachments/Screenshot.png?q1=foo\&q2=bar)
The only difference I am able to spot is the backslash before the ampersand. It seems that the plugin escapes the ampersand which in turn triggers a change event.
If I pass in this content instead,
onChange
is not called:![test-image](https://test.blob.net/foo/bar/1234/attachments/Screenshot.png?q1=foo\\&q2=bar)
Notice the double backslash before the ampersand.
This also seems to do the trick:![test-image](https://test.blob.net/foo/bar/1234/attachments/Screenshot.png?q1=foo&q2=bar)
Reproduction
Here is a codesandbox that reproduces the behaviour described above. As you can see in the console, the
onChange
is triggered after the first render without any interaction from the user or external changes to the markdown string.https://codesandbox.io/p/devbox/suspicious-breeze-x8sfzs
Expected behavior
I expect the
onChange
not to be called unless the user actually makes changes to the content.If escaping the URLs are necessary for it to be valid markdown, is there a helper method I could call instead to do the escaping of the content before passing it to the editor so that I can prevent the unwanted change event?
Another alternative would be to throw an error if the markdown passed to the editor is not valid markdown instead of converting it automatically and firing a callback. The this type of behaviour would be easier to spot and debug.
The text was updated successfully, but these errors were encountered: