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

[UI-REACT], fix preact by changing rollup options #248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

T-Damer
Copy link

@T-Damer T-Damer commented Aug 30, 2024

Related issue: #247

@kesha-antonov
Copy link

Please merge

@kesha-antonov
Copy link

kesha-antonov commented Oct 22, 2024

For future googlers temp fix is:

package.json

"scripts": {
    "buildTonConnect": "cd node_modules/@tonconnect/ui-react/packages/ui-react && ../../../../.bin/vite build && cd ../../../../..",
    "postinstall": "patch-package && yarn buildTonConnect"
    ...
},
"dependencies": {
    "@tonconnect/ui": "^2.0.9",
    "@tonconnect/ui-react": "ton-connect/sdk#5155e53d208c8cf01aea16752d58f9012d9f7138",
    ...
},
"devDependencies": {
    "@vitejs/plugin-react": "^4.3.3",
    "typescript": "^5.6.3",
    "vite": "^5.4.9",
    "vite-plugin-dts": "^4.2.4",
    ...
}

patches/@TonConnect+ui-react+2.0.0.patch

diff --git a/node_modules/@tonconnect/ui-react/packages/ui-react/vite.config.ts b/node_modules/@tonconnect/ui-react/packages/ui-react/vite.config.ts
index ac65a58..8d8c2c7 100644
--- a/node_modules/@tonconnect/ui-react/packages/ui-react/vite.config.ts
+++ b/node_modules/@tonconnect/ui-react/packages/ui-react/vite.config.ts
@@ -35,11 +35,13 @@ export default defineConfig({
       }
     },
     rollupOptions: {
-      external: ['react', 'react-dom', '@tonconnect/ui'],
+      external: ['react', 'react-dom', 'react-dom/client', 'react/jsx-runtime', '@tonconnect/ui'],
       output: {
         globals: {
           react: 'React',
           'react-dom': 'ReactDOM',
+          'react-dom/client': 'ReactDOMClient',
+          'react/jsx-runtime': 'ReactJSXRuntime',
           '@tonconnect/ui': 'TON_CONNECT_UI'
         }
       }

run yarn install

Change
import ... from '@tonconnect/ui-react'
to
import ... from '@tonconnect/ui-react/packages/ui-react/lib/index.cjs'

@T-Damer
Copy link
Author

T-Damer commented Oct 22, 2024

I just:

  1. Copied this repo, cd into folder
  2. Changed roullupOption in vite.config.ts to:
rollupOptions: {
      external: ['react', 'react-dom', 'react-dom/client', 'react/jsx-runtime', '@tonconnect/ui'],
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM',
          'react-dom/client': 'ReactDOMClient',
          'react/jsx-runtime': 'ReactJSXRuntime',
          '@tonconnect/ui': 'TON_CONNECT_UI'
        }
      }
  1. Ran yarn build
  2. Copied the output folder (/dist if I recall correctly) into my project (I used /lib directory)
  3. Import everything I need, like this:
import {
 useTonConnectUI,
 toUserFriendlyAddress,
 useTonWallet,
} from 'lib/ui-react'

PS: you may need to change tsconfig: "exclude": ["node_modules", "src/lib"]

@kodermax
Copy link

kodermax commented Nov 5, 2024

Why has this PR been pending for so long?

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.

3 participants