Fix Xdebug hang in packaged Electron apps#3125
Conversation
Skip mounting process.cwd() when it equals '/' to prevent hanging. In packaged Electron apps, process.cwd() returns '/' (root directory). The previous code attempted to mount the entire root filesystem using NODEFS, which caused the PHP runtime initialization to hang indefinitely. This fix checks if cwd is '/' and skips the mount operation in that case, allowing Xdebug to work properly in production Electron environments.
30e2b41 to
adbfba2
Compare
…art-when-using-built
|
While not mounting |
|
@adamziel that was my initial thought when looking at the changes, but I am able to debug with the packaged version of Studio and using NODEFS mount is not needed because:
So maybe we could remove EDIT: I have tested locally removing that mounting (commit 2fbf899) and debugging works fine for me using PHPStorm, I can add breakpoints and step through the code. Should I push the changes for review? |
2fbf899 to
67ab9f4
Compare
…art-when-using-built
|
This is weird! I remember we've tweaked this exact mount specifically to get the path mapping to work. Or was it the path mapping in the browser devtools and not in the IDE? 🤔 In which case we're missing a unit test to keep that part working. Let's get some input from @mho22 or @brandonpayton here. |
|
@adam @epeicher Before Xdebug 3.5, path mapping didn't exist and absolute paths were used to make Xdebug step debugging find files, this means PHP.wasm virtual filesystem needs to mount the current working directory to create these absolute paths. That is why we run :
But this could probably be replaced by IDEs path mappings and Xdebug 3.5 path mappings. I am currently working on an exploratory pull request. In the meantime we could merge this since it won't break the previous behavior and avoid breaking the Electron one. But this doesn't mean Xdebug will work correctly in Electron without IDEs path mappings. Edit: It seems a patch has been merged on Studio waiting for this issue to be fixed but we still can merge this one. |
|
Thanks for explanation and for merging this @mho22!
Yes, that's right, we merged a patch to this package to unblock the XDebug timeout for the release, but we plan to delete it after upgrading to this version. |
## Summary Follows up on #3125 in an attempt to finally resolve #3064. #3125 introduced a `fetch("main.js")` to bust the Safari cache and load that ES module after a page reload. That solution turned out to be, unfortunately, flaky. This PR retries to import `main.js` with a cache buster string, similarly to `import("main.js?_ts=178961653")`. It seems to have worked for me during testing. Fingers crossed it solves it once and for all! ## The Problem As documented in #3215, Safari sometimes fails with "TypeError: Importing a module script failed" when trying to import the main module after a new deployment. The previous solution (fetch + page reload) worked but was heavy-handed. ## Test plan 1. Open playground.wordpress.net in Safari on iOS 2. Plug it in to a Mac with a cable 3. Open devtools for that tab in Desktop Safari 4. Deploy this PR 5. Refresh the tab on iOS 7. Confirm the website reloaded correctly 8. If you also can see the "Failed to load main module" error in the console, this fix works. 9. If you can't, we don't know if it fully works yet.
Related to STU-1183
Summary
process.cwd()returns/in packaged Electron apps, and attempting to mount the entire root filesystem via NODEFS causes the runtime to hangcwdis/Problem
When running WordPress Playground CLI with Xdebug enabled inside a packaged Electron app, the application would hang indefinitely during PHP runtime initialization. This only occurred in production builds, not in development mode.
Root Cause
The
with-xdebug.tsfile mountsprocess.cwd()using NODEFS to allow Xdebug to sync with the debugger. In packaged Electron apps,process.cwd()returns/(the root filesystem), and attempting to mount/via NODEFS hangs the runtime as it tries to access the entire filesystem.Solution
Added a check to skip the NODEFS mount when
cwdis/. This is safe because:/, there's no meaningful project directory to mount anywayTest plan