-
Notifications
You must be signed in to change notification settings - Fork 16
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
monaco-editor vite blocker #200
Comments
@johnlindquist do we have a guide on how to run
I guess there is something else 😄 |
okay, I found this |
@suren-atoyan did you get the setup working? The easiest way would be to install the main release (it will set up the ~/.kit, ~/.knode, and ~/.kenv): https://github.com/johnlindquist/kitapp/releases/tag/v1.41.96 Then "npm i" and "npm run dev" should work. Again, it only breaks after "npm run build"
|
@johnlindquist I could manage to setup it up, now I run it on dev, and also I can debug it. It took some time due to a lack of docs though. Could you please tell me how I should build it and test the build version? |
I use the "m1" command from
My final command from the terminal looks like: You can remove the "--mac and --arm64" if you're not on an intel mac:
|
Also, after a build, you can access dev tools from the menubar icon->Debug-> Open dev tools |
that's what I do even in dev mode |
"m1" creates production "Kit.app". Is that not what you're seeing? |
@johnlindquist I spent a good amount of time on this thing, so let me share my findings. First of all, to use monaco we have two main options; either For the first option, you need a special treatment, if it's webpack you need an additional plugin if it's vite you have to import workers and set up The second option should have been working because it's less magic and we do not depend on the framework. For that, first, you need to copy the function ensureFirstBackSlash(str: string) {
return str.length > 0 && str.charAt(0) !== '/' ? `/${str}` : str;
}
function uriFromPath(_path: string) {
const pathName = path.resolve(_path).replace(/\\/g, '/');
return encodeURI(`file://${ensureFirstBackSlash(pathName)}`);
}
const vs = uriFromPath(path.join(__dirname, '../dist/monaco-editor/dev/vs'));
// note that it's "monaco-editor/dev" or "monaco-editor/min", but not "monaco-editor/esm"
loader.config({
paths: {
vs,
},
}); This should have been working, but your setup refuses to load anything with To easily check the local file restriction, in // this is temporary
loader.config({
paths: {
vs: `/Users/surenatoyan/projects/kitapp/dist/monaco-editor/dev/vs`,
},
}); I couldn't spend more time on this, but if you make electron to load local resources this should work. One more note: If you choose the second option to load monaco, do not forget to remove all direct imports of |
please check these and let me know about the progress, if it doesn't work, I'll do another iteration at the end of this week. In any case, it should be fixed 🙂 |
@suren-atoyan Thanks you so much for taking so much time to look into this 🙏 Second OptionI was using that "second option": Even though I'm using the
Since I felt it was getting too "hacky", I decided to put my efforts back towards "option one":
const vs =
process.env.NODE_ENV === 'development'
? path.join(process.cwd(), 'node_modules', 'monaco-editor', 'min', 'vs')
: path.join(__dirname, 'vs');
loader.config({ paths: { vs } }); then in the vite.config.ts:
Continuing with Option OneWhen I strip out almost all the code around the editor, the workers don't "crash". I'm not sure yet what the conflict is, but I'm going to keep adding/removing bits until I figure out exactly what is causing the crash. I have a feeling it's something really small and stupid... |
First LoadSo it appears that loading the typescript worker:
Which causes a re-render which:
Second Loadbut, if I force load the a SECOND TIME:
Strangely... It creates a second "monaco-aria-container" in the dom... 🙃 So things are still broken, but at least it seems "solvable" by preloading the editor/workers or something 🤔 @suren-atoyan Does that spark any ideas? |
I tried
there is nothing unsolvable 🙂 |
just in case, if you try to install another version of |
"Force load" meant:
I've been attempting to preload/load the editor before "step 1." so that it might work the first time, but no luck so far. Thanks for the caching tip! I'm new to vite so I'll make sure to keep an eye on it. (It's bedtime here, I'll check in my "progress" in the morning) |
@suren-atoyan Committed my ugly preload hack 🙃 https://github.com/johnlindquist/kitapp/blob/vite/src/App.tsx |
for some reason |
@johnlindquist that's still a hack obviously, but we can beautify it a little bit. First, we can move that "magic" part from I did these things, plus a few other cleanups, here is the PR 🙂 |
@suren-atoyan Thanks for the PR! ❤️ At least this is forcing me to clean up and organize things a bit (still a lot to do 😅) Re: "Enter" I don't know what's going on with "Enter" in prod... It also causes that "line rendering" in prod which I had to manually disable in options. I also had to add a hack in the "index.html" since it's causing multiple aria divs. It's so strange... None of that happens in dev 😥 |
I'm not exactly sure what that plugin is doing to the files that causes this behavior:
It seems like an odd setting to have in a plugin since an app can have multiple windows, some with Thanks so much for all of your help with this (and your patience with me). |
hey @johnlindquist 👋 Very happy that this is finally solved 😄 I told you there is nothing unsolvable 😄 And just in case, Let me know if you find out more about the issue. |
@suren-atoyan I believe the issue stemmed from the plugin converting the monaco-editor imports from esm to cjs causing the monaco Workers to crash when trying to import files. I'm not quite sure how it "recovered" after the crash with our hacky fixes... |
Your hypothesis makes sense, but yes, really, how it "recovered"? Could you please give me an update on this issue? Was adding nodeIntegration fixed the problem? |
Removing "nodeIntegration" from the vite plugin fixed it. I completely misunderstood the intent of that setting. It was the default and I assumed I needed it (since I'm using the setting in Electron): In Electron: In the vite plugin: 🤷♂️ |
I presume this issue can be closed @johnlindquist? |
Everything works great in dev, but after I build, the app silently breaks. I think it's from trying to load the typescript worker, but I'm lost.
Btw, here's the relevant "vite" branch and "editor.tsx" file:
https://github.com/johnlindquist/kitapp/blob/vite/src/components/editor.tsx#L25
I'm guessing it's something I'd have to change in my "vite.config.ts", but I've tried everything I can think of and I'm lost:
https://github.com/johnlindquist/kitapp/blob/vite/vite.config.ts
Here's a video showing the bug in the production build:
https://youtu.be/Lmusf_1stsQ
Here's a production build from the "vite" branch you should be able to try it on:
https://github.com/johnlindquist/kitapp/releases/tag/v1.41.96
The text was updated successfully, but these errors were encountered: