@@ -6,13 +6,13 @@ import Gio from "gi://Gio";
66import * as xml from "../langs/xml/xml.js" ;
77import * as postcss from "../lib/postcss.js" ;
88
9- import { settings } from "../util.js" ;
9+ import { settings , unstack } from "../util.js" ;
1010
1111import Internal from "./Internal.js" ;
1212import External from "./External.js" ;
1313import { getClassNameType } from "../overrides.js" ;
1414
15- import { assertBuildable , isPreviewable } from "./utils.js" ;
15+ import { isBuilderable , isPreviewable } from "./utils.js" ;
1616
1717// Workbench always defaults to in-process preview now if Vala is selected.
1818// Workbench will switch to out-of-process preview when Vala is run
@@ -101,10 +101,10 @@ export default function Previewer({
101101 function start ( ) {
102102 stop ( ) ;
103103 if ( handler_id_ui === null ) {
104- handler_id_ui = panel_ui . connect ( "updated" , update ) ;
104+ handler_id_ui = panel_ui . connect ( "updated" , schedule_update ) ;
105105 }
106106 if ( handler_id_css === null ) {
107- handler_id_css = code_view_css . connect ( "changed" , update ) ;
107+ handler_id_css = code_view_css . connect ( "changed" , schedule_update ) ;
108108 }
109109 }
110110
@@ -145,11 +145,7 @@ export default function Previewer({
145145 ) ;
146146
147147 let symbols = null ;
148- function update ( ) {
149- const builder = new Gtk . Builder ( ) ;
150- const scope = new BuilderScope ( ) ;
151- builder . set_scope ( scope ) ;
152-
148+ async function update ( ) {
153149 let text = panel_ui . xml . trim ( ) ;
154150 let target_id ;
155151 let tree ;
@@ -168,32 +164,29 @@ export default function Previewer({
168164
169165 if ( ! target_id ) return ;
170166
171- try {
172- assertBuildable ( tree ) ;
173- } catch ( err ) {
174- console . error ( err ) ;
175- return ;
176- }
167+ console . time ( "builderable" ) ;
168+ if ( ! ( await isBuilderable ( text ) ) ) return ;
169+ console . timeEnd ( "builderable" ) ;
170+
171+ const builder = new Gtk . Builder ( ) ;
172+ const scope = new BuilderScope ( ) ;
173+ builder . set_scope ( scope ) ;
177174
178175 registerSignals ( { tree, scope, symbols, template } ) ;
179176
177+ term_console . clear ( ) ;
178+
180179 try {
181- // For some reason this log warnings twice
182180 builder . add_from_string ( text , - 1 ) ;
183181 } catch ( err ) {
184- // The following while being obviously invalid
185- // does no produce an error - so we will need to strictly validate the XML
186- // before constructing the builder
187- // prettier-xml throws but doesn't give a stack trace
188- // <style>
189- // <class name="title-1"
190- // </style>
182+ if ( err instanceof GLib . MarkupError || err instanceof Gtk . BuilderError ) {
183+ console . warn ( err . message ) ;
184+ return ;
185+ }
191186 logError ( err ) ;
192187 return ;
193188 }
194189
195- term_console . clear ( ) ;
196-
197190 const object_preview = builder . get_object ( target_id ) ;
198191 if ( ! object_preview ) return ;
199192
@@ -215,6 +208,8 @@ export default function Previewer({
215208 symbols = null ;
216209 }
217210
211+ const schedule_update = unstack ( update , logError ) ;
212+
218213 function useExternal ( ) {
219214 if ( current === external ) return ;
220215 stack . set_visible_child_name ( "open_window" ) ;
0 commit comments