22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // TODO: migrate to package:web
6- // ignore: deprecated_member_use
7- import 'dart:html' ;
5+ import 'dart:js_interop' ;
86
97import 'package:http/http.dart' deferred as http show get;
8+ import 'package:web/web.dart' ;
109
1110typedef PopStateFn = void Function ();
1211
@@ -22,14 +21,15 @@ void setupPageUpdater(PopStateFn popStateFn) {
2221
2322 // initialize history with the current state
2423 window.history.replaceState (
25- {'html' : document.documentElement? .outerHtml} ,
24+ {'html' : document.documentElement? .outerHTML}. jsify () ,
2625 document.title,
2726 window.location.href,
2827 );
2928
3029 // handle back button updates
3130 window.onPopState.listen ((event) {
32- if (event.state case {'html' : final String htmlState? }) {
31+ final state = event.state.dartify ();
32+ if (state case {'html' : final String htmlState? }) {
3333 _update (
3434 htmlState,
3535 pushState: false ,
@@ -49,13 +49,13 @@ Document _update(
4949 // attributes. We could re-run the initialization, but storing the current
5050 // values and replacing the provided ones is simpler.
5151 final oldClasses = document.body! .className;
52- final doc = DomParser ().parseFromString (html, 'text/html' );
52+ final doc = DOMParser ().parseFromString (html. jsify () ! , 'text/html' );
5353 document.querySelector ('body' )! .replaceWith (doc.querySelector ('body' )! );
5454 document.body! .className = oldClasses;
5555 _popStateFn !();
5656 if (pushState) {
57- final title = doc.querySelector ('title' )? .text ;
58- window.history.pushState ({'html' : html}, title ?? '' , url);
57+ final title = doc.querySelector ('title' )? .textContent ;
58+ window.history.pushState ({'html' : html}. jsify () , title ?? '' , url);
5959 }
6060 return doc;
6161}
@@ -81,7 +81,7 @@ Future<void> updateBodyWithHttpGet({
8181 return ;
8282 }
8383 } catch (e, st) {
84- window. console.error (['Page replace failed.' , e, st]);
84+ console.error (['Page replace failed.' , e, st]. jsify () );
8585 }
8686 // fallback: reload the new URL
8787 window.location.href = navigationUrl ?? requestUri.toString ();
0 commit comments