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 nested hook call #18

Merged
merged 7 commits into from
May 11, 2023
Merged

Conversation

SukkaW
Copy link
Contributor

@SukkaW SukkaW commented May 9, 2023

The PR continues from #15.

The PR fixes these:

import { useA, useB, useC, useD, useE, useF, useG, useH } from 'whatever'

function Example(props) {
  let a = null;
  return useA(
    useB(),
    [useC(), 'array'],
    { d: useD(), [useE()]: useF(), ...useG() },
    `testA${useH()}testB`,
    useI() === useJ(),
    (a = useK()),
    ...useJ()
  );
}
import { useA, useB, useC } from 'whatever'

function Example(props) {
  let a = null;
  return { [useA()]: useB(), ...useC(), [`testA${useH()}testB`]: useI() === useJ(), assign: (a = useK()) }
}

The PR handles a lot more nested hook call cases. The unit test case is also added.

@SukkaW SukkaW changed the title Fix branched caching output Fix nested hook call May 9, 2023
@SukkaW SukkaW marked this pull request as draft May 10, 2023 03:39
@SukkaW SukkaW force-pushed the any-hook-in-any-expression branch from a580977 to 2610460 Compare May 10, 2023 05:08
@lxsmnsyc
Copy link
Owner

lxsmnsyc commented May 10, 2023

I'm thinking right now if we can scan the expression ahead of time and check if it has a hook call, opting-out of optimization, much like isConstant, but instead we return optimizedExpr(expr, undefined).

I feel like partial optimization is too complex for now.

@SukkaW
Copy link
Contributor Author

SukkaW commented May 10, 2023

I'm thinking right now if we can scan the expression ahead of time and check if it has a hook call, opting-out of optimization, much like isConstant, but instead we return optimizedExpr(expr, undefined).

I feel like partial optimization is too complex for now.

Yeah. I have noticed that, too. And that's exactly why I have converted the PR to the draft.

I am trying a different approach (which I haven't pushed yet!) to address the fix.

@SukkaW SukkaW marked this pull request as ready for review May 10, 2023 11:40
@SukkaW
Copy link
Contributor Author

SukkaW commented May 10, 2023

@lxsmnsyc I have refactored the bailout: bf78713 (#18)

@lxsmnsyc
Copy link
Owner

@SukkaW I don't think this covers everything yet. A correct implementation is really difficult so I guess I would discourage you on doing that for now. A check like isConstant in optimizeExpression is definitely ideal in here.

@SukkaW
Copy link
Contributor Author

SukkaW commented May 10, 2023

@SukkaW I don't think this covers everything yet. A correct implementation is really difficult so I guess I would discourage you on doing that for now. A check like isConstant in optimizeExpression is definitely ideal in here.

I have implemented is-contains-hook.ts based on the is-constant.ts in a191ae0 (#18)

@lxsmnsyc
Copy link
Owner

This looks great! Thank you. I'll expand from your work.

@SukkaW
Copy link
Contributor Author

SukkaW commented May 11, 2023

This looks great! Thank you. I'll expand from your work.

@lxsmnsyc My next PR will focus on merging is-contains-hook and is-constant into one file (to avoid duplicated code), and try to run the traverse only once. Will that affect your plan?

@lxsmnsyc
Copy link
Owner

@SukkaW You probably shouldn't. This is fine for 0.5.0. I have a plan for 0.6.0 to properly merge this all.

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