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: Issue 32: Verbose logging about useLayoutEffect on server render with web-export with toast component #33

Conversation

the-simian
Copy link
Contributor

  1. adds a line of code to prevent accessing function on server that causes verbose logging
  2. adds a prettierrc.json that matches the existing code style

…dd prettierrc.json to match single-quote-style in repo
@the-simian
Copy link
Contributor Author

the-simian commented Feb 5, 2024

Verification: The toast component still works normally on the web-export, IOS, and android builds after this change

Web (Blisk) Android (hardware)
image image

@the-simian the-simian changed the title Fix Verbose useLayoutEffect on server render Fix: Isse 42: Verbose useLayoutEffect on server render with web-export with toast component Feb 5, 2024
@the-simian
Copy link
Contributor Author

the-simian commented Feb 5, 2024

This fixes #32

@the-simian the-simian changed the title Fix: Isse 42: Verbose useLayoutEffect on server render with web-export with toast component Fix: Issue 42: Verbose useLayoutEffect on server render with web-export with toast component Feb 5, 2024
@the-simian the-simian changed the title Fix: Issue 42: Verbose useLayoutEffect on server render with web-export with toast component Fix: Issue 42: Verbose logging about useLayoutEffect on server render with web-export with toast component Feb 5, 2024
@the-simian the-simian changed the title Fix: Issue 42: Verbose logging about useLayoutEffect on server render with web-export with toast component Fix: Issue 32: Verbose logging about useLayoutEffect on server render with web-export with toast component Feb 5, 2024
Copy link
Owner

@mrzachnugent mrzachnugent left a comment

Choose a reason for hiding this comment

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

Thank you for contributing!

Can you add this as a custom hook?

In ~/lib/useIsomorphicLayoutEffect.tsx, can you add

import * as React from 'react';

export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect

And then use it here?

FYI: If you were to use import * as React from 'react' here, you would get the typescript error: "Cannot assign to 'useLayoutEffect' because it is a read-only property"

@the-simian
Copy link
Contributor Author

the-simian commented Feb 6, 2024

You bet, I think a custom hook is a better approach!

I will say we unfortunately probably still need to use the 'shim' least for now. In this codebase for our own code we can use the isomorphic useLayoutEffect, but the issue is actually inside of react-native-toast-messages on this line: https://github.com/calintamas/react-native-toast-message/blob/c9f6e08667d37f7d3f8a873226a1d670fb842554/src/components/AnimatedContainer.tsx#L121

Specifically:

  React.useLayoutEffect(() => {
    const newAnimationValue = isVisible ? 1 : 0;
    animate(newAnimationValue);
  }, [animate, isVisible]);

I was considering opening a PR on that repo at some point in the future to fix it there. Basically submitting some sort of isomorphic hook solution like you've proposed. If the problem wasn't inside somone else's module I think I'd have done this first

@the-simian
Copy link
Contributor Author

Update: I've added the hook for our own uses in situations where we'd call useLayoutEffect effect ourselves. I've left the existing shim in since its in a downstream module and I'm not sure how we'd get our hook in there. I can submit a PR to their repo directly in the future and we can then (probably) remove the shim.

Copy link
Owner

@mrzachnugent mrzachnugent left a comment

Choose a reason for hiding this comment

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

Thank you for the clarifications

lib/useIsomorphicLayoutEffect.tsx Outdated Show resolved Hide resolved
components/ui/toast.tsx Outdated Show resolved Hide resolved
@the-simian
Copy link
Contributor Author

Here is the referenced issue in the other repo and I've made all the other requested changes:
calintamas/react-native-toast-message#530

Copy link
Owner

@mrzachnugent mrzachnugent left a comment

Choose a reason for hiding this comment

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

Great! Thank you

@mrzachnugent mrzachnugent merged commit 5c75c7e into mrzachnugent:main Feb 7, 2024
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

2 participants