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

Add necessary mocks to build Next.js app #2873

Open
wants to merge 13 commits into
base: @mbert/add-react-compact
Choose a base branch
from

Conversation

m-bert
Copy link
Contributor

@m-bert m-bert commented Apr 22, 2024

Description

This PR adds necessary typescript changes in order to build Next.js app.

Test plan

I've tested this changes on branch with Next Example using yarn build.

@m-bert m-bert changed the title Add necessary types to build Next.js app Add necessary mocks to build Next.js app Apr 22, 2024
@m-bert m-bert marked this pull request as ready for review April 22, 2024 09:10
src/RNGestureHandlerModule.ts Show resolved Hide resolved
hitSlop?: Insets | undefined;
}

export default React.forwardRef<View, { rippleColor: any }>(
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't rippleColor be moved to RawButtonWebProps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If only it was so simple 😞 I've spent a lot of time racking my brain to get rid of this TS error and that was the only solution I've come up with. Well, maybe not the only one, but the other was to add {rippleColor: any} into createNativeWrapper:

const ComponentWrapper = React.forwardRef<
    React.ComponentType<any>,
    P & NativeViewGestureHandlerProps & {rippleColor: any}
  >((props, ref) => {

which I really don't like

Copy link
Member

Choose a reason for hiding this comment

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

🪄 summon @tjzel, help plz

Copy link
Contributor

Choose a reason for hiding this comment

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

👀

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any problem with this:

import * as React from 'react';
import { Insets, View } from '../ReactCompat';
import { RawButtonProps } from './GestureButtons';

interface RawButtonWebProps extends RawButtonProps {
  hitSlop?: Insets | undefined;
  rippleColor?: string | undefined;
}

export default React.forwardRef<View, RawButtonWebProps>(
  (props: RawButtonWebProps, ref) => (
    <View ref={ref} accessibilityRole="button" {...props} />
  )
);

Where should I look for the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I do 😞 Here's what I get:

image

This happens when I try to build Next app, doing lint check and tsc --noEmit in root gives no errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

@m-bert If it's not urgent, let's find an opportunity to work on this offline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tjzel It is not. Moreover, we already reverted one of the PRs that was a part of this whole process, so I think it will be the best to start with a discussion about what we want to achieve and which direction should we take.

Copy link
Contributor

Choose a reason for hiding this comment

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

MMMMMMMMMMMMMMMMMMMMMMMWNXKKKKKKKKKKXWMMMMMMMMMMMMMMMWWWWMMMMMMM
MMMMMMMMMMMMMMMWX0XWWNXK00KXXXNXXXX0OOKNNWWMMMMMMMMMN0kOKNMMMMMM
MMWXXWMMMMMMMW0dllkKK0OO0KKXXXXXXKK0OO0KKKXXNWMMMMMMW0dxKWMMMMMM
MW0loXMMMMMMWXOxk0KXXKOOOO00000KKKKKKKXXXXKKKKXNNMMMMWKXWMMMMMMM
W0c;oKMMMMMNK0KXXXK00OxdddxkkOOO000KKKXKK0KXXXXK0XWMMMMMMMMMMMMM
Xl',l0WWWWNKO00KK00Okxl::codkkOOOOOO0000OkO0KKK0OOKNWWMMMMMMMMMM
0;..'l0XXXKKKK0OkkOOkkoccdk0KXXKKK0OkkkOOkkkkkO0KKXKXXXNWMMMMMMM
NkoddxOKXXXNNXK00KKXXK0kk0XXXXXXXXK0kkOKXXXK000KXXXNXXK0KNMMMMMM
MMMNOkO0KKXXXKOO0KXXXK0OO0KKKKKKKK0OkxOKK00K00OOKXXXKK0Ok0WMMMMM
MMMXxdxkOOOOOkddkOO0OOxddxkOOOOOOOkxdodkxdxkkkxxxkOOOOkxod0NWMMM
MMMNxcloodddol::clooolc::cllooddoool:;:cloxkkkxdoldddooc:ldONMMM
MMMMKo;;;;;;;,,'',,,,,'''',,;;;;;;,,''',:ldxxddlc;;:;;;,:odxKMMM
WX00KKkl;,''''''''..'''''...........''',:cloolc:,''...';lood0WMM
Nd:ldONWXOxl;'''''.';cc,................',;cc:;,......,::clkNMMM
MKl:lxKMMMMWXOdlc;';kXk;..................,lxkxl'...',;;;:xNMMMM
MMKl:d0KXWMMMMWK0OkO0xc,,,,,;,,,,,,,;;,;;;l0WMWOol:;,;cxOKNMMMMM
MMM0l:;;ckXWMMMMMMMMXxl:,..............,:lONMMMMWWNK00XWMMMMMMMM
MMMMNXx,';lKWMMMMMMNXKKKx'            .okk0KKNWWMMMMMMMMMMMMMMMM
MMMMMMWOodONMWXOOOOo::col:;;;,'...',,,:c:;;;;cox0XWWWMMMMMMMMMMM
MMMMMMMMWXK0Okl;;c:'..'',,,,,;cc:::cllllc:;;,'',:dxkXMMMMMMMMMMM
MMMMMMMW0ol:;''';c:,.',,,,,;;:cllcclllccc::ccc:::lo0WMMMMMMMMMMM
MMMMMMMMNOo:;,..'''..',,,''.',:llllllcccccllc::::lOWMMMMMMMMMMMM
MMMMMMMMMWXx:'......',;;;,,,'.':clooollllolc:cc:cxNMMMMMMMMMMMMM
MMMMMMMMMMMW0c......';;;;;;;;'.';:looooooolcclccckWMMMMMMMMMMMMM
MMMMMMMMMMWXkc......',,,,''',;'.';cloooooolc::cclOWMMMMMMMMMMMMM
MMMMMMMMMNkc'........'',.. .::,..,:cllooool;,:c:oKMMMMMMMMMMMMMM
MMMMMMMN0l;,'........',;.  ......';:clloool'..,:dXMMMMMMMMMMMMMM
MMMMMMNk:;;,'.......',;:,   ....'',;:ccllll;..,co0WMMMMMMMMMMMMM
MMMMMWKo;;;,'......',,;::,....''''',;:cclllc;;cllxXWMMMMMMMMMMMM
MMMMNkl;;,,'......',,;;::;;,,,''''',;;:cccccccclllxXMMMMMMMMMMMM
MMMNOo:,'''.......'',;;;;;;,,,'''''',;;:::cccccccllOWMMMMMMMMMMM
MMMMWNk;'''........',,,,,,,,''''''''',;;;;::cccccccdXMMMMMMMMMMM
MMMMMNd'''.........'',,,,,''.........',;;:clllllllcl0MMMMMMMMMMM
MMMMM0:'''..........'''','...........';:cccccccccccl0MWNMMMMMMMM
MMMMWx,'''............';o:..........';;;;:::c:c:::coKN0KWMWNWMMM
MMMMXo'''......;,.....'lkl.........',,'..,;::::,.';cxkkKWNOONMMM
MMMMNd;,'.....;dc...  .lOk:'......',,....';;::;...':okkxkxdONMMM
MMMMWNK0c....'lkd,..  .;d00Oo,....,;'. .';:::cc,..,cdxoclokXWMMM
MMMMMMMWk,...,lxOxc;;,;;;:ldd:....'::,';cccccllc::cloooodkXWMMMM
MMMMMMMMXl...':ok0XXKK0Oc...'......,:ccccccccclllccoddxOKWMMMMMM
MMMMMMMMMKkko,.;cdk000ko;'..',,,,,'',,;::::cccccoxO0KXNWMMMMMMMM
MMMMMMMMMMMMNx,..',;c:,..''.',;;;;,,,,,;,,,;,,:dKWMMMMMMMMMMMMMM
MMMMMMMMMMMMMNx;,::,',,'..'''',;;;;;;;;;'.''':xXMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMWXKNNKo;,;;,''',;;;;;;;,,';:;,cONMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMWXKKkl;,,,:ccccc:::cc:;l0WMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMN0o:,,,,,,;;,,,,:xXMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMW0d:,,,'''',:d0WMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMW0o:,.'',ckNMMMMMMMMMMMMMMMMMMMMMMM

src/getReactNativeVersion.ts Outdated Show resolved Hide resolved
src/handlers/PressabilityDebugView.tsx Show resolved Hide resolved
(
RNGestureHandlerModule.attachGestureHandler as AttachGestureHandlerWeb
)(
(RNGestureHandlerModule as any).attachGestureHandlerWeb(
Copy link
Member

Choose a reason for hiding this comment

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

I'd love to avoid casting to any if possible. It will give no feedback in case the internal API changes.

Copy link
Contributor Author

@m-bert m-bert Apr 23, 2024

Choose a reason for hiding this comment

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

In that case I believe it will be the best to add ts-ignore. The problem here is that type of Gesture Handler Module comes from Spec which extends TurboModule and I don't want to change native implementation.

Copy link
Member

Choose a reason for hiding this comment

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

ts-ignore doesn't change much, since it will ignore any errors anyway. While we will likely catch any errors coming from changing module APIs, it would be great to see them immediately in types.

Previous approach, while not looking very nice, was accomplishing this at the cost of duplicating a type. Do we need to rely on the types from Spec on web?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about this approach?

Copy link
Member

Choose a reason for hiding this comment

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

That's better, but I'd like to avoid duplicating the definitions if possible. Have you tried adding the 4th optional argument to the attachGestureHandler? It should make it work without casting but I'm not sure how will it play with codegen.

You'd likely need to make some tricks to make both TS and codegen happy at the same time, but this should work:

type UnsafeMixed = unknown;

...
  attachGestureHandler: (
    handlerTag: number,
    newView: number,
    actionType: number,
    propsRef?: UnsafeMixed
  ) => void;
...

You would need to also make sure the native code still works, and likely update the generated specs we're using on the old arch.

src/web/handlers/FlingGestureHandler.ts Outdated Show resolved Hide resolved
src/web/handlers/LongPressGestureHandler.ts Outdated Show resolved Hide resolved
src/web/handlers/PanGestureHandler.ts Outdated Show resolved Hide resolved
src/web/handlers/TapGestureHandler.ts Outdated Show resolved Hide resolved
src/web/handlers/TapGestureHandler.ts Outdated Show resolved Hide resolved
@m-bert m-bert requested a review from j-piasecki April 25, 2024 12:06
j-piasecki pushed a commit that referenced this pull request May 7, 2024
)

## Description

This reverts commit e3e0b79.

#2835 was the first PR that was meant to introduce compatibility with
`Next.js`. Unfortunately, it broke types outside of our repository. Our
`tsconfig.json` has special flag, i.e. `moduleSuffixes`, which allows
`tsc` to look for `.native` files first. Most of our users do not have
this flag and they've run into `ts` problems, like this one:

```
'TextInput' refers to a value, but is being used as a type here. Did you mean 'typeof TextInput'?
```

Given that removing `moduleSuffixes` from `tsconfig` results in a bunch
of errors (and there are more of them that we may not be aware of), we
decided that it will be better to revert this change for now. It is not
necessary since we only need it to support `Next.js`. At first I thought
that #2873 may help, but unfortunately it doesn't.

Fixes #2889

## Test plan

1. Check that web, Android and iOS work as they did before
2. Check that code from [this
comment](#2835 (comment))
now does not throw any errors
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

3 participants