Skip to content

Commit 6e72a6e

Browse files
authored
[Xdebug Bridge] Correct error related to unresolved promises in bridge (#2422)
## Motivation for the change, related issues Resolves the [problem introduced](https://github.com/WordPress/wordpress-playground/pull/2411/files#r2229819528) in #2411: > The promise returned by `getPHPFile()` is never resolved and the PHP source code never loads in devtools
1 parent ac66883 commit 6e72a6e

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

packages/php-wasm/xdebug-bridge/src/lib/start-bridge.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type StartBridgeConfig = {
1414
localRoot?: string;
1515

1616
phpInstance?: PHP;
17-
getPHPFile?: (path: string) => Promise<string>;
17+
getPHPFile?: (path: string) => string | Promise<string>;
1818
};
1919

2020
export async function startBridge(config: StartBridgeConfig) {
@@ -58,21 +58,17 @@ export async function startBridge(config: StartBridgeConfig) {
5858
}
5959

6060
const getPHPFile = config.phpInstance
61-
? (path: string) =>
62-
new Promise<string>(() =>
63-
config.phpInstance!.readFileAsText(path)
64-
)
61+
? (path: string) => config.phpInstance!.readFileAsText(path)
6562
: config.getPHPFile
6663
? config.getPHPFile
67-
: (path: string) =>
68-
new Promise<string>(() => {
69-
// Default implementation: read from filesystem
70-
// Convert file:/// URLs to local paths
71-
const localPath = path.startsWith('file://')
72-
? path.replace('file://', '')
73-
: path;
74-
return readFileSync(localPath, 'utf-8');
75-
});
64+
: (path: string) => {
65+
// Default implementation: read from filesystem
66+
// Convert file:/// URLs to local paths
67+
const localPath = path.startsWith('file://')
68+
? path.replace('file://', '')
69+
: path;
70+
return readFileSync(localPath, 'utf-8');
71+
};
7672

7773
const phpFiles = getPhpFiles(phpRoot);
7874
return new XdebugCDPBridge(dbgpSession, cdpServer, {

packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface XdebugCDPBridgeConfig {
2828
knownScriptUrls: string[];
2929
remoteRoot?: string;
3030
localRoot?: string;
31-
getPHPFile(path: string): Promise<string>;
31+
getPHPFile(path: string): string | Promise<string>;
3232
}
3333

3434
export class XdebugCDPBridge {
@@ -45,7 +45,7 @@ export class XdebugCDPBridge {
4545
private xdebugConnected = false;
4646
private xdebugStatus = 'starting';
4747
private initFileUri: string | null = null;
48-
private readPHPFile: (path: string) => Promise<string>;
48+
private readPHPFile: (path: string) => string | Promise<string>;
4949
private remoteRoot: string;
5050
private localRoot: string;
5151

0 commit comments

Comments
 (0)