File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -359,7 +359,14 @@ export default class Component {
359
359
modifiedModelValues [ modelName ] = this . valueStore . get ( modelName ) ;
360
360
} ) ;
361
361
362
- const newElement = htmlToElement ( html ) ;
362
+ let newElement ;
363
+ try {
364
+ newElement = htmlToElement ( html ) ;
365
+ } catch ( error ) {
366
+ console . error ( 'There was a problem with the component HTML returned:' ) ;
367
+
368
+ throw error ;
369
+ }
363
370
// normalize new element into non-loading state before diff
364
371
this . hooks . triggerHook ( 'loading.state:finished' , newElement ) ;
365
372
Original file line number Diff line number Diff line change @@ -220,6 +220,10 @@ export function htmlToElement(html: string): HTMLElement {
220
220
html = html . trim ( ) ;
221
221
template . innerHTML = html ;
222
222
223
+ if ( template . content . childElementCount > 1 ) {
224
+ throw new Error ( `Component HTML contains ${ template . content . childElementCount } elements, but only 1 root element is allowed.` ) ;
225
+ }
226
+
223
227
const child = template . content . firstElementChild ;
224
228
if ( ! child ) {
225
229
throw new Error ( 'Child not found' ) ;
Original file line number Diff line number Diff line change @@ -365,4 +365,24 @@ describe('LiveController rendering Tests', () => {
365
365
366
366
await waitFor ( ( ) => expect ( test . element ) . toHaveTextContent ( '123' ) ) ;
367
367
} ) ;
368
+
369
+ it ( 'can understand comment in the response' , async ( ) => {
370
+ const test = await createTest ( { season : 'summer' } , ( data : any ) => `
371
+ <!-- messy comment -->
372
+ <div ${ initComponent ( data ) } >
373
+ The season is: ${ data . season }
374
+ </div>
375
+ ` ) ;
376
+
377
+ test . expectsAjaxCall ( 'get' )
378
+ . expectSentData ( test . initialData )
379
+ . serverWillChangeData ( ( data ) => {
380
+ data . season = 'autumn' ;
381
+ } )
382
+ . init ( ) ;
383
+
384
+ await test . component . render ( ) ;
385
+ // verify the component *did* render ok
386
+ expect ( test . element ) . toHaveTextContent ( 'The season is: autumn' ) ;
387
+ } ) ;
368
388
} ) ;
You can’t perform that action at this time.
0 commit comments