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] question in nuxt 3 #218

Open
1 task done
mahdi4187 opened this issue Jul 30, 2024 · 6 comments
Open
1 task done

[UI] question in nuxt 3 #218

mahdi4187 opened this issue Jul 30, 2024 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@mahdi4187
Copy link

mahdi4187 commented Jul 30, 2024

Your Question

hey guys

i use this, works for first view page in nuxt 3 but after page change and back to page get this error

Uncaught (in promise) DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "tc-root" has already been used with this registry

please guide me

Context

onMounted(() => {
  nuxt.hook('page:loading:end', () =>  initializeWalletConnect())
})
function initializeWalletConnect() {
  tonConnectUIInstance = new TonConnectUI({
    manifestUrl: `${url}/tonconnect-manifest.json`,
    buttonRootId: 'ton-connect'
  });

  tonConnectUIInstance.uiOptions = {
    twaReturnUrl: `https://t.me/${botUserName}`,
    uiPreferences: {
      theme: THEME.DARK,
      colorsSet: {
        [THEME.DARK]: {
          connectButton: {
            background: '#0950db',
          }
        }
      }
    }
  };
}

What have you tried so far?

No response

Relevant Code or Commands

No response

Documentation Check

  • Yes, I have checked the documentation.
@mahdi4187 mahdi4187 added the question Further information is requested label Jul 30, 2024
@glutaminefree
Copy link

Same error but on Vue 3 + Vue Router and without Nuxt.

@xcaptain
Copy link

Same error here using sveltekit, do you have a solution yet?

@slavnycoder
Copy link

Destroy method is needed.

@mahdi4187
Copy link
Author

mahdi4187 commented Nov 5, 2024

I fixed this

<script setup lang="ts">
import {TonConnectUIProvider} from '@townsquarelabs/ui-vue'

const colorMode = useColorMode();
const profitIsRun = useState("profitIsRun", () => false);
const {baseUrl,botUserName} = useRuntimeConfig().public

const options = {
  manifestUrl: `${baseUrl}/tonconnect-manifest.json`,
  twaReturnUrl: `https://t.me/${botUserName}`,
};

onMounted(() => {
  colorMode.preference = colorMode.value = "dark";
  window.Telegram?.WebApp.expand()
})
</script>
<template>
  <TonConnectUIProvider :options="options">
    <NuxtLayout>
      <NuxtPage />
    </NuxtLayout>
  </TonConnectUIProvider>
</template>

and to other page

<script setup lang="ts">
import { useTonConnectUI, TonConnectButton, useTonAddress } from '@townsquarelabs/ui-vue';

const tonConnectUI = useTonConnectUI();
const address = useTonAddress();

async function checkProofInYourBackend(wallet: any) {
    if (wallet) {
        console.log(wallet);
    }
}

onMounted(() => {
    checkProofInYourBackend(address.value)
})
</script>

<template>
    <TonConnectButton className="mt-3" />
</template>

@xcaptain
Copy link

xcaptain commented Nov 6, 2024

@mahdi4187 I don't understand your solution

@xcaptain
Copy link

xcaptain commented Nov 6, 2024

I have a solution found from: WICG/webcomponents#754

const defineCustomElement = CustomElementRegistry.prototype.define;
CustomElementRegistry.prototype.define = function define(name, constructor, options) {
    if (name == 'tc-root') {
        return;
    }
    return defineCustomElement.call(this, name, constructor, options);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants