@@ -261,16 +261,18 @@ def _process_component_request(
261261 key : component_request .data [key ] for key in sorted (component_request .data )
262262 }
263263
264- res = {
264+ result = {
265265 "id" : component_request .id ,
266266 "data" : updated_data ,
267267 "errors" : component .errors ,
268268 "calls" : component .calls ,
269269 "checksum" : generate_checksum (str (component_request .data )),
270270 }
271271
272+ render_not_modified = False
273+
272274 if partial_doms :
273- res .update ({"partials" : partial_doms })
275+ result .update ({"partials" : partial_doms })
274276 else :
275277 hash = generate_checksum (rendered_component )
276278
@@ -279,42 +281,46 @@ def _process_component_request(
279281 and (not return_data or not return_data .value )
280282 and not component .calls
281283 ):
282- raise RenderNotModified ()
284+ if not component .parent :
285+ raise RenderNotModified ()
286+ else :
287+ render_not_modified = True
283288
284- # Make sure that partials with comments or blank lines before the root element only return the root element
289+ # Make sure that partials with comments or blank lines before the root element
290+ # only return the root element
285291 soup = BeautifulSoup (rendered_component , features = "html.parser" )
286292 rendered_component = str (get_root_element (soup ))
287293
288- res .update (
294+ result .update (
289295 {
290296 "dom" : rendered_component ,
291297 "hash" : hash ,
292298 }
293299 )
294300
295301 if return_data :
296- res .update (
302+ result .update (
297303 {
298304 "return" : return_data .get_data (),
299305 }
300306 )
301307
302308 if return_data .redirect :
303- res .update (
309+ result .update (
304310 {
305311 "redirect" : return_data .redirect ,
306312 }
307313 )
308314
309315 if return_data .poll :
310- res .update (
316+ result .update (
311317 {
312318 "poll" : return_data .poll ,
313319 }
314320 )
315321
316322 parent_component = component .parent
317- parent_res = res
323+ parent_result = result
318324
319325 while parent_component :
320326 # TODO: Should parent_component.hydrate() be called?
@@ -340,12 +346,22 @@ def _process_component_request(
340346 }
341347 )
342348
343- parent_res .update ({"parent" : parent })
349+ if render_not_modified :
350+ # TODO: Determine if all parents have not changed and return a 304 if
351+ # that's the case
352+ # i.e. render_not_modified = render_not_modified and (parent hash test)
353+ pass
354+
355+ # If there is a parent dom and a child dom, remove the child dom because it is superfluous
356+ if parent .get ("dom" ) and result .get ("dom" ):
357+ del result ["dom" ]
358+
359+ parent_result .update ({"parent" : parent })
344360 component = parent_component
345361 parent_component = parent_component .parent
346- parent_res = parent
362+ parent_result = parent
347363
348- return res
364+ return result
349365
350366
351367def _handle_component_request (
0 commit comments