Telegram-Mini-Apps / telegram-apps

Made from scratch TypeScript packages, examples and documentation you will surely need to start developing on Telegram Mini Apps.
https://docs.telegram-mini-apps.com/
MIT License
740 stars 205 forks source link

[Feature]: retrieveLaunchParams return error, instead of throwing #382

Closed Mergemat closed 4 months ago

Mergemat commented 5 months ago

Is your feature request related to a problem? Please describe.

retrieveLaunchParams errors, breaking Next.js build process.

So in Next.js we should do this

let initData = "";
try {
  const { initDataRaw } = retrieveLaunchParams();
  initData = initDataRaw ?? "";
} catch {
    //
}

Approach above fixes the situation, but this is a lot of code for the data that we use very often.

Describe the solution you'd like

Maybe it could return errors instead of throwing, so using a hook will look something like this?

const {launchParams, errors, isError} = useLaunchParams(true);

if (isError) {
  return <p>{JSON.stringify(errors)}</p>;
}

Describe alternatives you've considered

No response

Additional context

No response

Mergemat commented 5 months ago

I see that errors array being created, but not returned. This feature was planned already? https://github.com/Telegram-Mini-Apps/tma.js/blob/c50df6da158925897768dfa65347142cd1c0dcd3/packages/sdk/src/launch-params/retrieveLaunchParams.ts#L12

heyqbnk commented 4 months ago

Could you explain how it breaks the Next.js build process?

Mergemat commented 4 months ago

Could you explain how it breaks the Next.js build process?

there is no launch params on build. so when code runs on build to create static pages, it gets an error from retrieveLaunchParams and stops build process

heyqbnk commented 4 months ago

You will never have launch parameters on the build stage. How do you expect it working properly?

Mergemat commented 4 months ago

You will never have launch parameters on the build stage. How do you expect it working properly?

not throwing errors, just returning them

Mergemat commented 4 months ago

now i need to block the whole app on server (like you did in next-template), and render only on client. but what's the point in using Next.js when your whole app is now client side

heyqbnk commented 4 months ago

but what's the point in using Next.js when your whole app is now client side

There is no point at all. Telegram Mini Apps is mostly a client side technology. You can use useLaunchParams(true) in case, you are using SSR.