From 5ba28e3a1c2744415b0d696301eef5e59de534fb Mon Sep 17 00:00:00 2001 From: Aran Donohue Date: Fri, 21 Feb 2025 01:29:12 -0800 Subject: [PATCH 1/2] fix: Use package:web to get HttpStatus (#749) * Use package:web to get HttpStatus * docs: add CHANGELOG.md entry --------- Co-authored-by: Moritz --- CHANGELOG.md | 1 + lib/src/shared/io_bits/io_bits.dart | 2 +- lib/src/shared/io_bits/io_bits_web.dart | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad86f53..98a24a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Upgrade to `package:lints` version 5.0.0 and Dart SDK version 3.5.0. * Upgrade `example/grpc-web` code. * Update xhr transport to migrate off legacy JS/HTML apis. +* Use `package:web` to get `HttpStatus` ## 4.0.1 diff --git a/lib/src/shared/io_bits/io_bits.dart b/lib/src/shared/io_bits/io_bits.dart index c7409b5..5f0dd1f 100644 --- a/lib/src/shared/io_bits/io_bits.dart +++ b/lib/src/shared/io_bits/io_bits.dart @@ -13,4 +13,4 @@ // See the License for the specific language governing permissions and // limitations under the License. -export 'io_bits_io.dart' if (dart.library.html) 'io_bits_web.dart'; +export 'io_bits_io.dart' if (dart.library.js_interop) 'io_bits_web.dart'; diff --git a/lib/src/shared/io_bits/io_bits_web.dart b/lib/src/shared/io_bits/io_bits_web.dart index 5290327..7f868d2 100644 --- a/lib/src/shared/io_bits/io_bits_web.dart +++ b/lib/src/shared/io_bits/io_bits_web.dart @@ -13,8 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// ignore: deprecated_member_use (#756) -export 'dart:html' show HttpStatus; +export 'package:web/web.dart' show HttpStatus; /// Unavailable on the web class InternetAddress {} From 6dfb4b43f39649cb324d9f132fff9e65bc48ed2b Mon Sep 17 00:00:00 2001 From: Aran Donohue Date: Fri, 21 Feb 2025 05:11:03 -0800 Subject: [PATCH 2/2] fix: Updates the grpc-web example to avoid dart:html (#748) * update: Migrate off legacy JS/HTML apis * update: use dart.library.js_interop in place of dart.library.html * update: dart format xhr_transport.dart and update dart sdk to v3.4.0 in workflows * update: use if instead of switch case in xhr_transport.dart * update: upgrade web package to v1.1.0 * refactor: use Uint8List for sending data over XHR rather than Int8List * refactor: eta-reduction of call to request.setRequestHeader * Convert grpc-web example to package:web --------- Co-authored-by: minoic Co-authored-by: Moritz --- example/grpc-web/lib/app.dart | 28 ++++++++++++++++++---------- example/grpc-web/pubspec.yaml | 1 + example/grpc-web/web/main.dart | 11 ++++------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/example/grpc-web/lib/app.dart b/example/grpc-web/lib/app.dart index c28c60e..8c0d982 100644 --- a/example/grpc-web/lib/app.dart +++ b/example/grpc-web/lib/app.dart @@ -14,9 +14,7 @@ // limitations under the License. import 'dart:async'; -// ignore: deprecated_member_use (#756) -import 'dart:html'; - +import 'package:web/web.dart'; import 'src/generated/echo.pbgrpc.dart'; class EchoApp { @@ -57,13 +55,23 @@ class EchoApp { } void _addMessage(String message, String cssClass) { - final classes = cssClass.split(' '); - querySelector('#first')!.after(DivElement() - ..classes.add('row') - ..append(Element.tag('h2') - ..append(SpanElement() - ..classes.add('label') - ..classes.addAll(classes) + document.querySelector('#first')!.after(HTMLDivElement() + ..classList.add('row') + ..append(HTMLHeadingElement.h2() + ..append(HTMLSpanElement() + ..classList.add('label') + ..classList.addAll(cssClass) ..text = message))); } } + +// The documentation of DOMTokenList.add implies it can handle multiple classes, +// but in Chrome at least it does not. +extension AddAll on DOMTokenList { + void addAll(String cssClass) { + final classes = cssClass.split(' '); + for (final c in classes) { + add(c); + } + } +} diff --git a/example/grpc-web/pubspec.yaml b/example/grpc-web/pubspec.yaml index 10f80ce..4719ec1 100644 --- a/example/grpc-web/pubspec.yaml +++ b/example/grpc-web/pubspec.yaml @@ -9,6 +9,7 @@ dependencies: grpc: path: ../../ protobuf: ^3.0.0 + web: ^1.1.0 dev_dependencies: build_runner: ^2.4.13 diff --git a/example/grpc-web/web/main.dart b/example/grpc-web/web/main.dart index bd740ff..997a4bd 100644 --- a/example/grpc-web/web/main.dart +++ b/example/grpc-web/web/main.dart @@ -12,23 +12,20 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - -// ignore: deprecated_member_use (#756) -import 'dart:html'; - import 'package:grpc/grpc_web.dart'; import 'package:grpc_web/app.dart'; import 'package:grpc_web/src/generated/echo.pbgrpc.dart'; +import 'package:web/web.dart'; void main() { final channel = GrpcWebClientChannel.xhr(Uri.parse('http://localhost:8080')); final service = EchoServiceClient(channel); final app = EchoApp(service); - final button = querySelector('#send') as ButtonElement; + final button = document.querySelector('#send') as HTMLButtonElement; button.onClick.listen((e) async { - final msg = querySelector('#msg') as TextInputElement; - final value = msg.value!.trim(); + final msg = document.querySelector('#msg') as HTMLInputElement; + final value = msg.value.trim(); msg.value = ''; if (value.isEmpty) return;