-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[BUG] - @nextui-org/snippet
Component Adds Extra Characters When Copying Code Snippets
#4225
Comments
Couldn't reproduce in latest version as well as canary branch. You may try on different editor. |
What editor? Do you know what this issue is about? Check here and copy code snippet and paste it in vs code: https://ithoughtspace.site/blog/how-to-build-a-progressive-web-app-pwa-with-nextjs-and-react-step-by-step-guide |
Issue is still there |
What I meant was asking you to test with other IDE other than VSCode just to see if it is a VSCode issue or not. Now with your updated example, I could reproduce the issue. However, I couldn't reproduce the issue using either latest / canary version, therefore I'd suggest you to upgrade to see if it's reproducible. If so, then probably it's related to other code. In this case, we will need a minimal reproducible sandbox for further investigation. |
Just do this: Check here and copy the code snippet and paste it into vs code: https://ithoughtspace.site/blog/how-to-build-a-progressive-web-app-pwa-with-nextjs-and-react-step-by-step-guide
|
@wingkwong Answer? |
@GautamPatoliya I've mentioned in previous reply already. I could reproduce the issue from your site. We need a minimal reproducible sandbox for further investigation since I couldn't reproduce the issue on my local which means it could be caused by external libraries. From inspecting the element, it seems like you're using |
This comment was marked as spam.
This comment was marked as spam.
Hello @GautamPatoliya I can Replicate your issue if I copy snippet from your website but I cannot replicate it on my end if I copy the following and run my app
This Issue also persists on other snippets that I copied from your site Can you make sure that the template string you have used in your app is not having invisible character |
@Dhananjay-JSR Could the issue be related to my use of Quill Editor and highlight.js? |
yes , it could be reason since highlight.js does inject it's own styling causing nextui snippet to act differently for text encoding I would say to switch to https://shiki.style/ and check if it fixes the issue Do Not Combine Highlighter + NextUI |
@GautamPatoliya I've already pointed out that it may be related to |
@wingkwong I have not just randomly tagged people, they're the collaborators. |
@Dhananjay-JSR Thank you sir |
NextUI Version
2.2.9
Describe the bug
The
Snippet
component from@nextui-org/snippet
adds invisible characters (e.g., non-breaking spaces) when using the built-in copy functionality. This results in formatting issues and errors when the copied code is pasted into a code editor. For instance, JSON code becomes invalid with errors like"Property keys must be doublequoted"
due to extra hidden characters.Actual Behavior
The copied code includes extra invisible characters, likely non-breaking spaces (
\u00A0
), which result in:"Property keys must be doublequoted"
.For example, the pasted code looks like this (with invisible characters causing issues):
Notice how some spaces are incorrectly formatted (non-breaking spaces).
Technical Analysis
The issue appears to be related to how the
Snippet
component processes and renders the code internally. During the copy operation:\u00A0
) or other hidden formatting characters are added.Proposed Solution
Sanitize the Copied Content:
.replace(/\u00A0/g, " ")
or equivalent sanitization.Allow Customization:
onCopy
) that lets users customize the copy functionality or sanitize the copied content.Update Documentation:
Snippet
component.Environment
14.4.0
119.0.0
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
npx create-next-app@latest my-next-app cd my-next-app npm install @nextui-org/react
Snippet
component as shown in the example below:Snippet
component.Expected behavior
The copied code should match the original snippet exactly, with no additional characters or formatting artifacts.
Screenshots or Videos
Operating System Version
Browser
Chrome
The text was updated successfully, but these errors were encountered: