Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: usage of layoutSize.value doesn't contain width or height causin… #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

antoniofranciscoandrade
Copy link

@antoniofranciscoandrade antoniofranciscoandrade commented Oct 2, 2022

Problem:

ChartPath doesn't render sometimes because layoutSize is initialized as 0 on ChartContext and is not being updated, causing all values multiplied by either layoutSize.value.width or layoutSize.value.height to be equal to NaN.

In addition, the path created using useDerivedValue is running on another thread and is not picking up the update on layoutSize when the following block runs :

useEffect(() => {
    layoutSize.value = { height, width };
  }, [height, layoutSize, width]);

Solution:

Initialize width and height on ChartPathProvider and set it to either the values that are being passed as props or the ones on layoutSize.value. Use these values for all calculations to make sure nothing is being multiplied by an undefined value.

On ChartPath, use width and height from props instead of setting these on layoutSize using an useEffect to prevent useDerivedValue from using any stale values. Also added [currData.value, prevData.value, smoothingStrategy.value, width, height] as dependencies when calling useDerivedValue to avoid further use of stale data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants