Skip to content

Commit

Permalink
Fix a bug with rendering of the root component
Browse files Browse the repository at this point in the history
There was a problem with calling `ReactDOMClient.createRoot()` on a container that has already been passed to `createRoot()` before. Let's move the provider logic into a separate file to make sure the entry point file will be run only once.
  • Loading branch information
kkosiorowska committed Nov 13, 2023
1 parent d6a45bc commit 71226eb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
10 changes: 0 additions & 10 deletions dapp/src/App.tsx

This file was deleted.

29 changes: 29 additions & 0 deletions dapp/src/DApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react"
import { useEmbedFeatureFlag } from "./hooks"
import { LedgerWalletAPIProvider } from "./providers"
import { LOCAL_STORAGE_EMBED } from "./constants"

function DApp() {
const { isEmbed } = useEmbedFeatureFlag()
if (isEmbed === "true") return <h1>Ledger live - Acre dApp</h1>
return <h1>Acre dApp</h1>
}

function DAppWrapper() {
const { enableIsEmbedFeatureFlag } = useEmbedFeatureFlag()

const params = new URLSearchParams(window.location.search)
const isEmbed = params.get(LOCAL_STORAGE_EMBED)

if (isEmbed) {
enableIsEmbedFeatureFlag()
return (
<LedgerWalletAPIProvider>
<DApp />
</LedgerWalletAPIProvider>
)
}
return <DApp />
}

export default DAppWrapper
24 changes: 2 additions & 22 deletions dapp/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
import React from "react"
import ReactDOM from "react-dom/client"
import App from "./App"
import { LedgerWalletAPIProvider } from "./providers"
import { LOCAL_STORAGE_EMBED } from "./constants"
import { useEmbedFeatureFlag } from "./hooks"

function DAppProvider() {
const { enableIsEmbedFeatureFlag } = useEmbedFeatureFlag()

const params = new URLSearchParams(window.location.search)
const isEmbed = params.get(LOCAL_STORAGE_EMBED)

if (isEmbed) {
enableIsEmbedFeatureFlag()
return (
<LedgerWalletAPIProvider>
<App />
</LedgerWalletAPIProvider>
)
}
return <App />
}
import DAppWrapper from "./DApp"

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<DAppProvider />
<DAppWrapper />
</React.StrictMode>,
)

0 comments on commit 71226eb

Please sign in to comment.