Skip to content

Commit 1f21013

Browse files
committed
Clean up and notes
1 parent 6eaecd2 commit 1f21013

2 files changed

Lines changed: 39 additions & 31 deletions

File tree

packages/devtools_app/lib/src/shared/primitives/url_utils.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ String? mapLegacyUrl(String url) {
2828
// http://localhost:123/#/?page=inspector&uri=ws://...
2929
final isRootRequest = uri.path == '/' || uri.path.endsWith('/devtools/');
3030
if (isRootRequest && uri.fragment.isNotEmpty) {
31+
// Note: If there is a ?compiler= query parameter, we remove it from before
32+
// the hash then add it back in as a query parameter at the end.
33+
// See https://github.com/flutter/devtools/issues/9612 for details.
3134
final hasJsParam = url.contains(_jsCompilerParam);
3235
final hasWasmParam = url.contains(_wasmCompilerParam) && !hasJsParam;
3336
final basePath = uri.path;
3437
// Convert the URL by removing the fragment separator.
3538
final newUrl = url
36-
.replaceAll(_wasmCompilerParam, '')
3739
.replaceAll(_jsCompilerParam, '')
40+
.replaceAll(_wasmCompilerParam, '')
3841
// Handle localhost:123/#/inspector?uri=xxx
3942
.replaceFirst('/#/', '/')
4043
// Handle localhost:123/#?page=inspector&uri=xxx
@@ -44,8 +47,8 @@ String? mapLegacyUrl(String url) {
4447
var newUri = Uri.parse(newUrl);
4548
final queryParams = {
4649
...newUri.queryParameters,
47-
if (hasWasmParam) 'compiler': 'wasm',
4850
if (hasJsParam) 'compiler': 'js',
51+
if (hasWasmParam) 'compiler': 'wasm',
4952
};
5053
newUri = newUri.replace(queryParameters: queryParams);
5154
final page = newUri.queryParameters['page'];

packages/devtools_app/test/shared/primitives/url_utils_test.dart

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,48 @@ void main() {
6666
expect(mapLegacyUrl('$prefix/#/?foo=bar'), '$prefix/?foo=bar');
6767
});
6868

69-
for (final compilerValue in ['js', 'wasm']) {
70-
group('with ?compiler=$compilerValue query param', () {
71-
test(
72-
'moves ?compiler=$compilerValue from before hash to after path',
73-
() {
74-
final newUrl = '$prefix/inspector?compiler=$compilerValue';
69+
group(
70+
'with "compiler" query param (https://github.com/flutter/devtools/issues/9612)',
71+
() {
72+
for (final compilerValue in ['js', 'wasm']) {
73+
test(
74+
'moves ?compiler=$compilerValue from before hash to after path',
75+
() {
76+
final newUrl = '$prefix/inspector?compiler=$compilerValue';
77+
expect(
78+
mapLegacyUrl(
79+
'$prefix/?compiler=$compilerValue#/inspector',
80+
),
81+
newUrl,
82+
);
83+
expect(
84+
mapLegacyUrl(
85+
'$prefix/?compiler=$compilerValue#/?page=inspector',
86+
),
87+
newUrl,
88+
);
89+
},
90+
);
91+
92+
test('handles additional query parameters', () {
93+
final newUrl =
94+
'$prefix/inspector?foo=bar&compiler=$compilerValue';
7595
expect(
76-
mapLegacyUrl('$prefix/?compiler=$compilerValue#/inspector'),
96+
mapLegacyUrl(
97+
'$prefix/?compiler=$compilerValue#/inspector?foo=bar',
98+
),
7799
newUrl,
78100
);
79101
expect(
80102
mapLegacyUrl(
81-
'$prefix/?compiler=$compilerValue#/?page=inspector',
103+
'$prefix/?compiler=$compilerValue#/?page=inspector&foo=bar',
82104
),
83105
newUrl,
84106
);
85-
},
86-
);
87-
88-
test('handles additional query parameters', () {
89-
final newUrl =
90-
'$prefix/inspector?foo=bar&compiler=$compilerValue';
91-
expect(
92-
mapLegacyUrl(
93-
'$prefix/?compiler=$compilerValue#/inspector?foo=bar',
94-
),
95-
newUrl,
96-
);
97-
expect(
98-
mapLegacyUrl(
99-
'$prefix/?compiler=$compilerValue#/?page=inspector&foo=bar',
100-
),
101-
newUrl,
102-
);
103-
});
104-
});
105-
}
107+
});
108+
}
109+
},
110+
);
106111
});
107112
}
108113
});

0 commit comments

Comments
 (0)