reflex/reflex/components/core
Masen Furer d767dc5fc7
[REF-2802] Foreach should respect modifications to children (#3263)
* Unit tests for add_style and component styles with foreach

The styles should be correctly applied for components that are rendered as part
of a foreach.

* [REF-2802] Foreach should respect modifications to children

Components are mutable, and there is logic that depends on walking through the
component tree and making modifications to components along the way. These
modifications _must_ be respected by foreach for consistency.

Modifications necessary to fix the bug:

* Change the hash function in `_render` to get a hash over the render_fn's
  `__code__` object. This way we get a stable hash without having to call the
  render function with bogus values.
* Call the render function once during `create` and save the result as a child
  of the Foreach component (tree walks will modify this instance).
* Directly render the original (and possibly modified) child component instead
  of calling the render_fn again and creating a new component instance at
  render time.

Additional changes because they're nice:

* Deprecate passing `**props` to `rx.foreach`. No one should have been
  doing this anyway, because it just does not work in any reasonable way.
* Raise `ForeachVarError` when the iterable type is Any
* Raise `ForeachRenderError` when the render function does not take 1 or 2 args.
* Link to the foreach component docs when either of those errors are hit.
* Change the `iterable` arg in `create` to accept `Var[Iterable] | Iterable`
  for better typing support (and remove some type: ignore comments)
* Simplify `_render` and `render` methods -- remove unused and potentially
  confusing code.

* Fixup: `to_bytes` requires `byteorder` arg before py3.11
2024-05-09 15:04:26 -07:00
..
layout add center / spacer / hstack / vstack in radix/themes/layout (#2331) 2024-01-30 15:39:22 -08:00
__init__.py Refactor upload component and add styled upload component (#3035) 2024-04-24 13:45:22 -07:00
banner.py use dict instead of set to store hooks (#2995) 2024-04-03 17:13:42 -07:00
banner.pyi generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
client_side_routing.py Refactor chakra components into separate folder (#2315) 2023-12-21 09:52:08 -08:00
client_side_routing.pyi [REF-2524] Tuple unpacking should apply at component level (#3062) 2024-04-11 14:04:19 -07:00
colors.py Get rx.color working with fstrings (#2562) 2024-02-09 17:06:55 -08:00
cond.py add_style api (#3202) 2024-05-06 16:59:11 -07:00
debounce.py [REF-2789] Graceful deprecation of rx.input.root and rx.input.input (#3249) 2024-05-08 14:39:22 -07:00
debounce.pyi extend rx.input allowed types (#3149) 2024-04-24 16:04:56 -07:00
foreach.py [REF-2802] Foreach should respect modifications to children (#3263) 2024-05-09 15:04:26 -07:00
html.py [REF-2574] Default width for Stack (+children) and default padding for container (#3104) 2024-04-30 13:15:57 -07:00
html.pyi generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
match.py add_style api (#3202) 2024-05-06 16:59:11 -07:00
responsive.py use radix box instead of chakra one for responsive elements (#2921) 2024-03-25 15:16:48 -07:00
upload.py [REF-2574] Default width for Stack (+children) and default padding for container (#3104) 2024-04-30 13:15:57 -07:00
upload.pyi Refactor upload component and add styled upload component (#3035) 2024-04-24 13:45:22 -07:00