reflex/tests
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
..
compiler Remove deprecations for 0.5.0 (#3222) 2024-05-07 08:55:42 -07:00
components [REF-2802] Foreach should respect modifications to children (#3263) 2024-05-09 15:04:26 -07:00
middleware [REF-201] Separate on_load handler from initial hydration (#1847) 2023-11-30 12:21:15 -08:00
states RED-1052/rx.State as Base State (#2146) 2023-11-29 09:43:33 -08:00
utils allow optional props with None default value (#3179) 2024-05-01 13:33:38 -07:00
__init__.py RED-1052/rx.State as Base State (#2146) 2023-11-29 09:43:33 -08:00
conftest.py [REF-201] Separate on_load handler from initial hydration (#1847) 2023-11-30 12:21:15 -08:00
test_app.py [REF-2643] Throw Errors for duplicate Routes (#3155) 2024-05-03 12:15:40 -07:00
test_attribute_access_type.py Improved get_attribute_access_type tests (#3180) 2024-05-01 17:13:23 -07:00
test_base.py Rename pynecone to reflex (#1236) 2023-06-25 16:56:55 -07:00
test_config.py Clean up config and app API (#3197) 2024-05-02 18:15:28 -07:00
test_db_config.py Rename pynecone to reflex (#1236) 2023-06-25 16:56:55 -07:00
test_event.py [REF-2273] Implement .setvar special EventHandler (#3163) 2024-05-01 17:13:55 -07:00
test_init.py Lendemor/improve coverage (#2988) 2024-04-04 14:31:43 +02:00
test_model.py [REF-2658] Alembic should use batch mode for autogenerate (#3223) 2024-05-06 18:34:55 -07:00
test_prerequisites.py [REF-2676][REF-2751] Windows Skip ARM devices on bun install + Telemetry (#3212) 2024-05-06 09:50:05 -07:00
test_route.py [REF-2643] Throw Errors for duplicate Routes (#3155) 2024-05-03 12:15:40 -07:00
test_state_tree.py [REF-1988] API to Get instance of Arbitrary State class (#2678) 2024-02-27 13:02:08 -08:00
test_state.py Remove deprecations for 0.5.0 (#3222) 2024-05-07 08:55:42 -07:00
test_style.py Handle component namespaces in global styles (#2630) 2024-02-15 16:03:10 -08:00
test_telemetry.py [REF-2676][REF-2751] Windows Skip ARM devices on bun install + Telemetry (#3212) 2024-05-06 09:50:05 -07:00
test_testing.py Clean up config and app API (#3197) 2024-05-02 18:15:28 -07:00
test_var.py allow set in var.contains (#3113) 2024-04-18 20:00:18 -07:00