flyntwp / flynt

Component based WordPress starter theme, powered by ACF Pro and Timber, optimized for a11y and fast page load results.
https://flyntwp.com
MIT License
735 stars 84 forks source link

The nested component inherits the parent context data even without explicit parameter passing. #579

Open mahmoud-alawad opened 1 day ago

mahmoud-alawad commented 1 day ago

Describe the bug Nested components unexpectedly have access to the parent component's context data, even when no parameters or props are explicitly passed to them. This causes unexpected behavior and potential data leakage, leading to unintended side effects in the application.

To Reproduce Steps to reproduce the behavior:

  1. Create a parent component with some context-based data or state.
  2. Add a nested component inside the parent component.
  3. Without passing any props or parameters, try to access the parent context from the nested component.
  4. Observe that the nested component can access the parent context data.

Expected behavior The nested component should not have access to the parent context data unless explicitly passed via props or another intentional mechanism.

Screenshots 2024-11-21_14-11

To prevent the issue in the example, the element property must be explicitly passed across all project files, ensuring consistent behavior and avoiding unintended context sharing. as down here

2024-11-21_14-12

The context must be reset at the root level each time the component is rendered to ensure a clean state and prevent unintended data persistence across renders.

timohubois commented 1 day ago

@mahmoud-alawad Nice catch, and many thanks for reporting this!

It would be great if you could create a pull request (PR) with a suggestion on how this issue can be resolved. Would that be an option for you?

mahmoud-alawad commented 1 day ago

@timohubois May have a look on this pr https://github.com/flyntwp/flynt/pull/580