sandpack icon indicating copy to clipboard operation
sandpack copied to clipboard

Feature request: feature for view console

Open kuduzow opened this issue 4 years ago • 9 comments

Tell us how you think we can improve Sandpack

It would be useful to have component like <SandpackConsole> that renders... a sandpack's console.

Packages affected

  • [x] sandpack-client (probably)
  • [x] sandpack-react

How would your idea work?

It might be a component that renders console or props like <SandpackPreview console> to include console into preview.

Do you have any examples of how you would like to see us implement it?

It depends on implementation way. The first example right on codesandbox.io ("Console" button on the bottom of preview).

Another way is something like this:

localhost_3000_read_html-and-css_tags

kuduzow avatar Nov 26 '21 20:11 kuduzow

Hey @kuduzow, that would be great!

I have added your feature request to our internal backlog which we use to prioritize what to build next. We can't make any promises about the timing, but it's on the list!

If you'd like to work on this feature with us, please create a pull request and we'll help you along the way.

For others landing on this issue, feel free to add more context or simply leave a thumbs up 👍 on this comment if you find this feature useful.

danilowoz avatar Dec 03 '21 15:12 danilowoz

Hi @danilowoz, I was wondering how the following code preview is created (link here): Screen Shot 2022-01-13 at 10 19 59 PM

It looks as if it's using CodeSandbox Embedding, but it doesn't use an iframe. Any idea how to implement something like this? (No iframe + with console feature)

Thank you!

rvlewerissa avatar Jan 13 '22 15:01 rvlewerissa

Hey @rvlewerissa. The link you sent uses CodeSandbox Embedding, which supports the console component and is wrapped in an iframe. However, we still don't have this component properly working on Sandpack, but we're trying to priority it, as this would be very valuable for the development experience.

We can't make any promise of when we will ship it, but we've been working hard to release it as soon as possible.

danilowoz avatar Jan 13 '22 15:01 danilowoz

@danilowoz Thanks for the really quick response! I just discovered that the example I gave does actually use an iframe, I overlooked 😅

Thanks for the hard work on this feature! Looking forward to it!

rvlewerissa avatar Jan 13 '22 16:01 rvlewerissa

Hey all! I'd like to hear your thoughts about this feature and get to understand what is the best approach for this:

  • I'm curious to know what kind of feature the Console component cannot miss?
  • Can you provide a great example of what would you consider an excellent console component?
  • Are you happy with the current CodeSandbox console component?

Feel free to drop any message here, and 👍 which one you like the most

danilowoz avatar Feb 02 '22 10:02 danilowoz

Hi @danilowoz!

Overall, I'm pretty happy with the CodeSandbox console. I like that it has a clear button, just like the browser console.

For Sandpack, I'm hoping that there will be a standalone component (SandpackConsole) so that I can build my own layouts with it. I'm less interested in a tab for the console. I'll either want to always show the console, or never show it.

My usecase: occasionally, my sandpacks will be demonstrating console output rather than a live preview. Sometimes, I want to show a particular dev warning. In other cases, I have little JS-based exercises, and the goal is for the user to edit the code and then check the console to see the logged output (rather than checking the preview pane to see the UI).

It might also be good to include timestamps? It can be useful to know when an item was logged. Or, alternatively, maybe the console could be automatically cleared when the code re-runs?

joshwcomeau avatar Mar 04 '22 13:03 joshwcomeau

I am building a code-teaching tool, so starting off with easy examples of JS functions that simply log to the console is important. I plan to write some testing functions that verify the logged output is correct, in order to provide instant feedback to the student. I've already found your example of capturing console.log data with if (msg.type === "console" && msg.codesandbox) @danilowoz, so thanks for that! But, being able to easily display the console for the student would be just what I need.

JoeShep avatar Mar 14 '22 19:03 JoeShep

My use case is that our components log message to show that things are happening. It would be helpful to for our users to open the console and see these messages stream in as they interact in the preview.

nicksrandall avatar Mar 22 '22 14:03 nicksrandall

It'd be great if the console logs came with the associated line numbers and file names. I've attached a screenshot of Chrome console logs that show the console log along with file name and line numbers.

Screen Shot 2022-07-15 at 5 06 49 PM

nimeshnayaju avatar Jul 16 '22 00:07 nimeshnayaju

Hey @danilowoz , I might be able to work on this. Can you point me to right direction so that I can explore a bit and decide If I can do it or not.

hussamkhatib avatar Aug 11 '22 08:08 hussamkhatib

Hey @hussamkhatib, thanks. But currently, it's working in progress on https://github.com/codesandbox/sandpack/pull/546

There are still a few challenging there, but hopefully I'll be able to ship it on the upcoming weeks

danilowoz avatar Aug 11 '22 08:08 danilowoz

Hey all! I'm excited to share that we have a beta version of SandpackConsole 🎉

It's meant to be a light version of the browser console, meaning that it will not support all console types or some very specific cases. The idea is to keep Sandpack light and modular, so for any other advanced case, I'd recommend going for console-feed.

Here's a sandbox with the component! - Plus, I would really appreciate it if we could exhaustively test this new component and report any eventual problems in this issue.

localhost_6006_iframe html_id=components-console--preset args= viewMode=story

Documentation is coming next! But, here's a summary:

  • New hook: useSandpackConsole;
  • New component: SandpackConsole;
  • New option: <Sandpack options={{ showConsole: true }} />;

danilowoz avatar Aug 19 '22 17:08 danilowoz

First of all thanks a lot for this feature! It's exactly what I was looking for 🙌

I got a small question: is it currently possible to clear the console between renders?

iampava avatar Jan 19 '23 20:01 iampava

Hey, thanks!

I don't think it's possible now, but if you wish this feature, please create another issue, and then we can address it. It must be something around here: when it gets a message from a refresh or similar, then clean the logs.

danilowoz avatar Jan 20 '23 09:01 danilowoz

@danilowoz thanks. Added a feature idea: https://github.com/codesandbox/sandpack/issues/692

iampava avatar Jan 24 '23 10:01 iampava