reflex/tests/components
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
..
base generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
core [REF-2802] Foreach should respect modifications to children (#3263) 2024-05-09 15:04:26 -07:00
datadisplay Top-level namespace tweaks (#2523) 2024-02-05 11:14:02 -08:00
el Lendemor/improve coverage (#2988) 2024-04-04 14:31:43 +02:00
forms [REF-2574] Default width for Stack (+children) and default padding for container (#3104) 2024-04-30 13:15:57 -07:00
graphing Lendemor/improve coverage (#2988) 2024-04-04 14:31:43 +02:00
layout generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
lucide add_style api (#3202) 2024-05-06 16:59:11 -07:00
media Use rx.el.img as rx.image (#2558) 2024-02-08 14:44:53 -08:00
radix add_style api (#3202) 2024-05-06 16:59:11 -07:00
typography Remove deprecations for 0.5.0 (#3222) 2024-05-07 08:55:42 -07:00
__init__.py Add basic unit tests (#7) 2022-11-20 14:34:25 -08:00
test_component_future_annotations.py [REF-2272] Support declaring EventHandlers directly in component (#2952) 2024-03-29 06:26:07 -07:00
test_component_state.py [REF-2265] ComponentState: scaffold for copying State per Component instance (#2923) 2024-03-29 09:22:25 -07:00
test_component.py [REF-2802] Foreach should respect modifications to children (#3263) 2024-05-09 15:04:26 -07:00
test_tag.py fixed issue with hypens (#2450) 2024-01-26 14:14:46 -08:00