nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 181 forks source link

[v2] Upgrade Solito to Support Next.js 13 #216

Closed nandorojo closed 2 years ago

nandorojo commented 2 years ago

To try this:

yarn add solito@next13

Closes #202

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
solito ✅ Ready (Inspect) Visit Preview Nov 25, 2022 at 4:35PM (UTC)
solito-s9oj ❌ Failed (Inspect) Nov 25, 2022 at 4:35PM (UTC)
with-custom-fonts ✅ Ready (Inspect) Visit Preview Nov 25, 2022 at 4:35PM (UTC)
1 Ignored Deployment | Name | Status | Preview | Updated | | :--- | :----- | :------ | :------ | | **solito-app** | ⬜️ Ignored ([Inspect](https://vercel.com/fernandorojo/solito-app/9tBQWKD2kyPpqy4XM2L3sBDMqp8f)) | | Nov 25, 2022 at 4:35PM (UTC) |
chrisarts commented 2 years ago

Did you experiment with the app folder ? I try to reproduce the document initialprops in the RootLayout but no luck, keeping the _document file doest work either.

chrisarts commented 2 years ago

Also expo next adapter just upgrate to support next13 take a look: https://github.com/expo/expo-cli/tree/main/packages/next-adapter#readme

ebg1223 commented 2 years ago

submitted PR #230 to fix error on expo due to updated nextjs useRouter hook.

nandorojo commented 2 years ago

Did you experiment with the app folder ? I try to reproduce the document initialprops in the RootLayout but no luck, keeping the _document file doest work either.

Not yet. This will require a new approach to injecting styles and such, without _document.

If you want to try, see this: https://beta.nextjs.org/docs/styling/css-in-js

I'm not sure if react-native-web supports this or not.

I think we'd need to add this to the root layout:

import { useServerInsertedHTML } from 'next/navigation';
import { AppRegistry } from 'react-native'

// ...
useServerInsertedHTML(() => {
     // where does Main come from in Next 13?
    AppRegistry.registerComponent('Main', () => Main)
    // @ts-ignore
    const { getStyleElement } = AppRegistry.getApplication('Main')

    return <>{getStyleElement()}</>;
  });
macrozone commented 1 year ago

Did you experiment with the app folder ? I try to reproduce the document initialprops in the RootLayout but no luck, keeping the _document file doest work either.

Not yet. This will require a new approach to injecting styles and such, without _document.

If you want to try, see this: https://beta.nextjs.org/docs/styling/css-in-js

I'm not sure if react-native-web supports this or not.

I think we'd need to add this to the root layout:

import { useServerInsertedHTML } from 'next/navigation';
import { AppRegistry } from 'react-native'

// ...
useServerInsertedHTML(() => {
     // where does Main come from in Next 13?
    AppRegistry.registerComponent('Main', () => Main)
    // @ts-ignore
    const { getStyleElement } = AppRegistry.getApplication('Main')

    return <>{getStyleElement()}</>;
  });

did you found a solution for that?

AwakenedMind commented 1 year ago

Any updates on this

nandorojo commented 1 year ago

Sigh, random pings.

I opened a PR at #397 to add app directory support. Maybe one of you can help figure out how to get useServerInsertedHTML to work with React Native.

Gabrola commented 1 year ago

@nandorojo check the tamagui starter app https://github.com/tamagui/tamagui/blob/master/starters/next-expo-solito/apps/next/app/TamaguiProvider.tsx

nandorojo commented 1 year ago

interesting...does Main still work here? may as well try 🤷‍♂️

nandorojo commented 1 year ago
Screenshot 2023-06-01 at 6 59 56 PM

Wow, can't believe I got this working lol.

Gabrola commented 1 year ago

@nandorojo Woot! 🎉

interesting...does Main still work here? may as well try 🤷‍♂️

I think Main actually does nothing here and the registerComponent function only is only called to trigger the generation of the RN CSS so you can fetch it using getStyleElement, pretty sure if you pass it an empty component it will still work. Also, I think this might be unperformant as it would register the app on each re-render.

Can you try this instead and see if it works? Follows roughly what's in the next.js docs here

  const [reactNativeApp] = useState(() => {
    AppRegistry.registerComponent('Main', () => () => null);
    // @ts-ignore
    return AppRegistry.getApplication('Main');
  });

  useServerInsertedHTML(() => reactNativeApp.getStyleElement());
chrisarts commented 1 year ago

@nandorojo Woot! 🎉

interesting...does Main still work here? may as well try 🤷‍♂️

I think Main actually does nothing here and the registerComponent function only is only called to trigger the generation of the RN CSS so you can fetch it using getStyleElement, pretty sure if you pass it an empty component it will still work. Also, I think this might be unperformant as it would register the app on each re-render.

Can you try this instead and see if it works? Follows roughly what's in the next.js docs here

  const [reactNativeApp] = useState(() => {
    AppRegistry.registerComponent('Main', () => () => null);
    // @ts-ignore
    return AppRegistry.getApplication('Main');
  });

  useServerInsertedHTML(() => reactNativeApp.getStyleElement());

Actually yes, Im not even using the app registry and it works normally, just needs to import the .css with RNW reset.