reflex/tests/components/core
Masen Furer 4f7ccb57bc
[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-10 20:27:39 -07:00
..
__init__.py rx.color to work with conditional vars (#2546) 2024-02-08 11:45:15 -08:00
test_banner.py Radix 3.0 (#3159) 2024-04-25 08:33:29 -07:00
test_colors.py Update CodeBlock class to accept rx.color in custom_style (#3168) 2024-05-01 14:48:33 -07:00
test_cond.py generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
test_debounce.py generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
test_foreach.py [REF-2802] Foreach should respect modifications to children (#3263) 2024-05-10 20:27:39 -07:00
test_html.py [REF-2574] Default width for Stack (+children) and default padding for container (#3104) 2024-04-30 13:15:57 -07:00
test_match.py generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
test_responsive.py generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
test_upload.py Refactor upload component and add styled upload component (#3035) 2024-04-24 13:45:22 -07:00