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

chore: move start screen skipping to ui and away from state machine #4799

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

thaddmt
Copy link
Contributor

@thaddmt thaddmt commented Nov 30, 2023

Description of changes

Issue #, if available

Description of how you validated changes

Checklist

  • Have read the Pull Request Guidelines
  • PR description included
  • Relevant documentation is changed or added (and PR referenced)
  • yarn test passes and tests are updated/added
  • No side effects or sideEffects field updated

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@thaddmt thaddmt requested a review from a team as a code owner November 30, 2023 23:36
Copy link

changeset-bot bot commented Nov 30, 2023

🦋 Changeset detected

Latest commit: b960bc5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/ui-react-liveness Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -38,6 +38,7 @@ interface LivenessCheckProps {
streamDisplayText: Required<StreamDisplayText>;
errorDisplayText: Required<ErrorDisplayText>;
components?: FaceLivenessDetectorComponents;
beginLivenessCheck: () => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this new prop affect customers, or is this only used internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only used internally

@thaddmt thaddmt requested a review from reesscot December 8, 2023 21:26
});
}, [send]);

React.useLayoutEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we have a compelling reason for useLayoutEffect here think useEffect should suffice. useLayoutEffect use cases are related to mutating the DOM/performing layout measurements and is documented to be potential performance bottleneck

const [state, send] = useActor(service);
const isStartView = state.matches('start');

const beginLivenessCheck = React.useCallback(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as i am a supporter of deduping, think in this case it makes sense to move the body of beginLivenessCheck inside the useLayoutEffect where it is called and keep the existing beginLivenessCheck here where it currently is. Cuts down on memoization overhead in LivenessCheck , allows for this PR to be a simpler change, and prevents additional coupling between FaceLivenessDetectorCore/LivenessCheck

@@ -43,6 +43,21 @@ export default function FaceLivenessDetectorCore(
},
});

const [state, send] = useActor(service);
const isStartView = state.matches('start');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disableStartScreen and isStartView read as somewhat contradicting one another imo, and since the existing declarations of isStartView are declared as:

const isStartView = state.matches('start') || state.matches('userCancel');

Maybe we can have a variable name spaced as something like shouldBeginLivenessCheck , example:

const shouldBeginLivenessCheck = disableStartScreen && state.matches('start');

Which would simplify the logic inside/deps required in the callback passed to useLayoutEffect

Comment on lines -240 to -244
const beginLivenessCheck = React.useCallback(() => {
send({
type: 'BEGIN',
});
}, [send]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in FaceLivenessDetectorCore, think the beginLivenessCheck declaration should remain here. Additionally, we don't need useCallback here, beginLivenessCheck is just being passed to a Button which is not an expensive re-render, and the Button is only rendered when isStartView is true

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.

None yet

6 participants