reflex/reflex/components
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
..
base [REF-2524] Tuple unpacking should apply at component level (#3062) 2024-04-11 14:04:19 -07:00
chakra add toast component (#3186) 2024-05-03 12:09:11 -07:00
core [REF-2802] Foreach should respect modifications to children (#3263) 2024-05-10 20:27:39 -07:00
datadisplay add_style api (#3202) 2024-05-06 16:59:11 -07:00
el extend rx.input allowed types (#3149) 2024-04-24 16:04:56 -07:00
gridjs [REF-2524] Tuple unpacking should apply at component level (#3062) 2024-04-11 14:04:19 -07:00
lucide Remove deprecations for 0.5.0 (#3222) 2024-05-07 08:55:42 -07:00
markdown Remove deprecations for 0.5.0 (#3222) 2024-05-07 08:55:42 -07:00
media Refactor chakra components into separate folder (#2315) 2023-12-21 09:52:08 -08:00
moment generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
next [REF-2524] Tuple unpacking should apply at component level (#3062) 2024-04-11 14:04:19 -07:00
plotly [REF-2524] Tuple unpacking should apply at component level (#3062) 2024-04-11 14:04:19 -07:00
radix form: default width="100%" (#3261) 2024-05-10 20:27:39 -07:00
react_player [REF-2524] Tuple unpacking should apply at component level (#3062) 2024-04-11 14:04:19 -07:00
recharts [REF-2524] Tuple unpacking should apply at component level (#3062) 2024-04-11 14:04:19 -07:00
sonner add toast component (#3186) 2024-05-03 12:09:11 -07:00
suneditor generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
tags [REF-2682] Foreach over dict uses Tuple arg value (#3160) 2024-04-25 09:10:55 -07:00
__init__.py add toast component (#3186) 2024-05-03 12:09:11 -07:00
component.py Remove deprecations for 0.5.0 (#3222) 2024-05-07 08:55:42 -07:00
literals.py Chakra input component type_ prop literal (#2292) 2023-12-18 15:43:51 -08:00