Skip to content

Commit

Permalink
feat(react): 小程序开发支持config传入的appId (#15835)
Browse files Browse the repository at this point in the history
Co-authored-by: tony chen <[email protected]>
  • Loading branch information
yechunxi and zhiqingchen authored Jul 10, 2024
1 parent 59ab4cf commit 96c8652
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/taro-plugin-react/src/runtime/connect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Current, document, getPageInstance, incrementId, injectPageInstance } from '@tarojs/runtime'
import { CONTAINER, Current, document, getPageInstance, incrementId, injectPageInstance } from '@tarojs/runtime'
import { EMPTY_OBJ, ensure, hooks } from '@tarojs/shared'

import { reactMeta } from './react-meta'
Expand Down Expand Up @@ -198,11 +198,14 @@ export function createReactApp (
}

function renderReactRoot () {
let appId = 'app'
if (process.env.TARO_PLATFORM === 'web') {
appId = config?.appId || appId
const appId = config?.appId || 'app'
let container = document.getElementById(appId)
if (container == null) {
const appContainer = document.getElementById(CONTAINER)
container = document.createElement(appId)
container.id = appId
appContainer?.appendChild(container)
}
const container = document.getElementById(appId)
if ((react.version || '').startsWith('18')) {
const root = ReactDOM.createRoot(container)
root.render?.(h(AppWrapper))
Expand Down

0 comments on commit 96c8652

Please sign in to comment.