-
Notifications
You must be signed in to change notification settings - Fork 83
modifying DWDS Injector to always inject client and introduce useDwdsWebSocketConnection flag #2629
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
Open
jyameo
wants to merge
6
commits into
dart-lang:main
Choose a base branch
from
jyameo:jy-webserver-bug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee198cd
modifying injector to always inject client and introduce runMainAtSta…
jyameo dd16b7d
mark fields as deprecated
jyameo 47a6634
added method to mark application as completed to avoid calling main()…
jyameo ba9d21a
Merge branch 'main' into jy-webserver-bug
jyameo 0f57f00
added a flag to determine the communication protocol; temporirily use…
jyameo 1418a19
merged main
jyameo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,25 +30,21 @@ const _clientScript = 'dwds/src/injected/client'; | |
/// to include the injected DWDS client, enabling debugging capabilities | ||
/// and source mapping when running in a browser environment. | ||
/// | ||
/// The `_injectDebuggingSupportCode` flag determines whether debugging-related | ||
/// functionality should be included: | ||
/// - When `true`, the DWDS client is injected, enabling debugging features. | ||
/// - When `false`, debugging support is disabled, meaning the application will | ||
/// run without debugging. | ||
/// | ||
/// This separation allows for scenarios where debugging is not needed or | ||
/// should be explicitly avoided. | ||
/// TODO(yjessy): Remove this when the DWDS WebSocket connection is implemented. | ||
/// The `_useDwdsWebSocketConnection` flag determines the communication protocol: | ||
/// - When `true`, uses a socket-based implementation. | ||
/// - When `false`, uses Chrome-based communication protocol. | ||
class DwdsInjector { | ||
final Future<String>? _extensionUri; | ||
final _devHandlerPaths = StreamController<String>(); | ||
final _logger = Logger('DwdsInjector'); | ||
final bool _injectDebuggingSupportCode; | ||
final bool _useDwdsWebSocketConnection; | ||
|
||
DwdsInjector({ | ||
Future<String>? extensionUri, | ||
bool injectDebuggingSupportCode = true, | ||
bool useDwdsWebSocketConnection = false, | ||
}) : _extensionUri = extensionUri, | ||
_injectDebuggingSupportCode = injectDebuggingSupportCode; | ||
_useDwdsWebSocketConnection = useDwdsWebSocketConnection; | ||
|
||
/// Returns the embedded dev handler paths. | ||
/// | ||
|
@@ -108,17 +104,15 @@ class DwdsInjector { | |
await globalToolConfiguration.loadStrategy.trackEntrypoint( | ||
entrypoint, | ||
); | ||
// If true, inject the debugging client and hoist the main function | ||
// to enable debugging support. | ||
if (_injectDebuggingSupportCode) { | ||
body = await _injectClientAndHoistMain( | ||
body, | ||
appId, | ||
devHandlerPath, | ||
entrypoint, | ||
await _extensionUri, | ||
); | ||
} | ||
// Always inject the debugging client and hoist the main function. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means we're injecting the client when doing AMD + web-server, which wasn't the case before unless |
||
body = await _injectClientAndHoistMain( | ||
body, | ||
appId, | ||
devHandlerPath, | ||
entrypoint, | ||
await _extensionUri, | ||
_useDwdsWebSocketConnection, | ||
); | ||
body += await globalToolConfiguration.loadStrategy.bootstrapFor( | ||
entrypoint, | ||
); | ||
|
@@ -154,6 +148,7 @@ Future<String> _injectClientAndHoistMain( | |
String devHandlerPath, | ||
String entrypointPath, | ||
String? extensionUri, | ||
bool useDwdsWebSocketConnection, | ||
) async { | ||
final bodyLines = body.split('\n'); | ||
final extensionIndex = bodyLines.indexWhere( | ||
|
@@ -172,6 +167,7 @@ Future<String> _injectClientAndHoistMain( | |
devHandlerPath, | ||
entrypointPath, | ||
extensionUri, | ||
useDwdsWebSocketConnection, | ||
); | ||
result += ''' | ||
// Injected by dwds for debugging support. | ||
|
@@ -203,6 +199,7 @@ Future<String> _injectedClientSnippet( | |
String devHandlerPath, | ||
String entrypointPath, | ||
String? extensionUri, | ||
bool useDwdsWebSocketConnection, | ||
) async { | ||
final loadStrategy = globalToolConfiguration.loadStrategy; | ||
final buildSettings = loadStrategy.buildSettings; | ||
|
@@ -221,6 +218,7 @@ Future<String> _injectedClientSnippet( | |
'window.\$dartEmitDebugEvents = ${debugSettings.emitDebugEvents};\n' | ||
'window.\$isInternalBuild = ${appMetadata.isInternalBuild};\n' | ||
'window.\$isFlutterApp = ${buildSettings.isFlutterApp};\n' | ||
'window.\$useDwdsWebSocketConnection = $useDwdsWebSocketConnection;\n' | ||
'${loadStrategy is DdcLibraryBundleStrategy ? 'window.\$hotReloadSourcesPath = "${loadStrategy.hotReloadSourcesUri.toString()}";\n' : ''}' | ||
'${loadStrategy.loadClientSnippet(_clientScript)}'; | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.