-
Notifications
You must be signed in to change notification settings - Fork 47
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
Calling createTSClient stops console.log functioning #101
Comments
Thinking a bit more about this I think we have a few options here.
public constructor(protected ts: any) {
// Overriding the console.log method so that we can store the logs
console.oldLog = console.log
console.log = (value) => {
// For some reason, the first 'incoming' log is always an instance of TSClient. Ignoring it
if (!(value instanceof TSClient)) {
console.oldLog(value)
this.logs.push(value)
}
}
} This should work, in that if the page embeds run-wasm and calls
My concern with anything except the second option is that some pages like to do things like log every redux action, and even if the page isn't logging you can't trust third party libraries not to. Mixing page logs and code logs in output has the potential to be really confusing. Maybe it won't be an issue in practice though? And the second option feels limiting, especially in the context of teaching. Anyone else got any thoughts or solutions that I haven't thought of? |
I started looking around at how other people are handling this for TS playgrounds and found this same category of issues happening with the folks building the Microsoft ts playground. Taking a look at how they approach the problem might be useful! |
Describe the bug
When a page calls
createTSClient
from@run-wasm/ts
itsconsole.log
function is silently broken. This is because that functions calls theTSClient
constructor:This is not sandboxed in any way by the browser, so calling it overrides
console.log
with a function that no longer logs messagesTo Reproduce
I've created a replit showing this: https://ConsoleLogOverride.mcintyre94.repl.co
Replit seems to have an issue loading ATM so you may need to use the edit link: https://replit.com/@mcintyre94/ConsoleLogOverride#pages/index.js (can run the app from here)
createTSClient
console.log
has been overwrittenExpected behavior
Calling
createTSClient
should not affect the caller's ability to log.I'm not 100% sure but maybe we should have the overwritten
console.log
also callconsole.oldLog
? This would mean that logs in the editor are printed to the browser console as well as captured to be displayed as output - probably not a bad thing? That'd be a one line fix and we wouldn't need to try to figure out a way to isolate the console change, which I suspect we can't do in the browser context anyway.Using
console.oldLog(...)
in the caller works correctly as a workaround for now.Screenshots
Desktop (please complete the following information):
Additional context
The page in my replit has the following code:
The text was updated successfully, but these errors were encountered: