@@ -260,16 +260,18 @@ def _process_component_request(
260260 key : component_request .data [key ] for key in sorted (component_request .data )
261261 }
262262
263- res = {
263+ result = {
264264 "id" : component_request .id ,
265265 "data" : updated_data ,
266266 "errors" : component .errors ,
267267 "calls" : component .calls ,
268268 "checksum" : generate_checksum (str (component_request .data )),
269269 }
270270
271+ render_not_modified = False
272+
271273 if partial_doms :
272- res .update ({"partials" : partial_doms })
274+ result .update ({"partials" : partial_doms })
273275 else :
274276 hash = generate_checksum (rendered_component )
275277
@@ -278,42 +280,46 @@ def _process_component_request(
278280 and (not return_data or not return_data .value )
279281 and not component .calls
280282 ):
281- raise RenderNotModified ()
283+ if not component .parent :
284+ raise RenderNotModified ()
285+ else :
286+ render_not_modified = True
282287
283- # Make sure that partials with comments or blank lines before the root element only return the root element
288+ # Make sure that partials with comments or blank lines before the root element
289+ # only return the root element
284290 soup = BeautifulSoup (rendered_component , features = "html.parser" )
285291 rendered_component = str (get_root_element (soup ))
286292
287- res .update (
293+ result .update (
288294 {
289295 "dom" : rendered_component ,
290296 "hash" : hash ,
291297 }
292298 )
293299
294300 if return_data :
295- res .update (
301+ result .update (
296302 {
297303 "return" : return_data .get_data (),
298304 }
299305 )
300306
301307 if return_data .redirect :
302- res .update (
308+ result .update (
303309 {
304310 "redirect" : return_data .redirect ,
305311 }
306312 )
307313
308314 if return_data .poll :
309- res .update (
315+ result .update (
310316 {
311317 "poll" : return_data .poll ,
312318 }
313319 )
314320
315321 parent_component = component .parent
316- parent_res = res
322+ parent_result = result
317323
318324 while parent_component :
319325 # TODO: Should parent_component.hydrate() be called?
@@ -339,12 +345,22 @@ def _process_component_request(
339345 }
340346 )
341347
342- parent_res .update ({"parent" : parent })
348+ if render_not_modified :
349+ # TODO: Determine if all parents have not changed and return a 304 if
350+ # that's the case
351+ # i.e. render_not_modified = render_not_modified and (parent hash test)
352+ pass
353+
354+ # If there is a parent dom and a child dom, remove the child dom because it is superfluous
355+ if parent .get ("dom" ) and result .get ("dom" ):
356+ del result ["dom" ]
357+
358+ parent_result .update ({"parent" : parent })
343359 component = parent_component
344360 parent_component = parent_component .parent
345- parent_res = parent
361+ parent_result = parent
346362
347- return res
363+ return result
348364
349365
350366def _handle_component_request (
0 commit comments