Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions packages/app/src/prompt/PromptGetCodeModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ const closeModal = () => {
const container = ref<HTMLDivElement | null>(null)
const error = ref<string | null>(null)
const ReactGetCodeModalContents = ref<GetCodeModalContentsShape | null>(null)
const reactRoot = ref<Root | null>(null)
const containerReactRootMap = new WeakMap<HTMLElement, Root>()
const promptStore = usePromptStore()

const maybeRenderReactComponent = () => {
if (!ReactGetCodeModalContents.value || !!error.value) {
if (!ReactGetCodeModalContents.value || !!error.value || !container.value) {
return
}

Expand All @@ -63,19 +63,32 @@ const maybeRenderReactComponent = () => {
},
})

if (!reactRoot.value) {
reactRoot.value = window.UnifiedRunner.ReactDOM.createRoot(container.value)
// Store the react root in a weak map keyed by the container. We do this so that we have a reference
// to it that's tied to the container value but absolutely do not want to use vue to do the tracking.
// If vue tracks it (e.g. using a ref) it creates proxies that do not play nicely with React in
// production
let reactRoot = containerReactRootMap.get(container.value)

if (!reactRoot) {
reactRoot = window.UnifiedRunner.ReactDOM.createRoot(container.value) as Root
containerReactRootMap.set(container.value, reactRoot)
}

reactRoot.value?.render(panel)
reactRoot.render(panel)
}

const unmountReactComponent = () => {
if (!ReactGetCodeModalContents.value || !container.value) {
return
}

reactRoot.value?.unmount()
const reactRoot = containerReactRootMap.get(container.value)

if (!reactRoot) {
return
}

reactRoot.unmount()
}

onMounted(maybeRenderReactComponent)
Expand Down
25 changes: 19 additions & 6 deletions packages/app/src/prompt/PromptMoreInfoNeededModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ const closeModal = () => {
const container = ref<HTMLDivElement | null>(null)
const error = ref<string | null>(null)
const ReactMoreInfoNeededModalContents = ref<MoreInfoNeededModalContentsShape | null>(null)
const reactRoot = ref<Root | null>(null)
const containerReactRootMap = new WeakMap<HTMLElement, Root>()
const promptStore = usePromptStore()

const maybeRenderReactComponent = () => {
if (!ReactMoreInfoNeededModalContents.value || !!error.value) {
if (!ReactMoreInfoNeededModalContents.value || !!error.value || !container.value) {
return
}

Expand All @@ -65,19 +65,32 @@ const maybeRenderReactComponent = () => {
},
})

if (!reactRoot.value) {
reactRoot.value = window.UnifiedRunner.ReactDOM.createRoot(container.value)
// Store the react root in a weak map keyed by the container. We do this so that we have a reference
// to it that's tied to the container value but absolutely do not want to use vue to do the tracking.
// If vue tracks it (e.g. using a ref) it creates proxies that do not play nicely with React in
// production
let reactRoot = containerReactRootMap.get(container.value)

if (!reactRoot) {
reactRoot = window.UnifiedRunner.ReactDOM.createRoot(container.value) as Root
containerReactRootMap.set(container.value, reactRoot)
}

reactRoot.value?.render(panel)
reactRoot.render(panel)
}

const unmountReactComponent = () => {
if (!ReactMoreInfoNeededModalContents.value || !container.value) {
return
}

reactRoot.value?.unmount()
const reactRoot = containerReactRootMap.get(container.value)

if (!reactRoot) {
return
}

reactRoot.unmount()
}

onMounted(maybeRenderReactComponent)
Expand Down
6 changes: 3 additions & 3 deletions packages/driver/cypress/e2e/commands/prompt/prompt.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ describe('src/cy/commands/prompt', () => {
// TODO: add more tests when cy.prompt is built out, but for now this just
// verifies that the command executes without throwing an error
// @ts-expect-error - this will not error when we actually release the experimentalPromptCommand flag
cy.prompt('Hello, world!')
cy.prompt(['Hello, world!'])

cy.visit('http://www.barbaz.com:3500/fixtures/dom.html')

cy.origin('http://www.barbaz.com:3500', () => {
// @ts-expect-error - this will not error when we actually release the experimentalPromptCommand flag
cy.prompt('Hello, world!')
cy.prompt(['Hello, world!'])
})
})

Expand All @@ -37,6 +37,6 @@ describe('src/cy/commands/prompt', () => {

cy.visit('http://www.foobar.com:3500/fixtures/dom.html')
// @ts-expect-error - this will not error when we actually release the experimentalPromptCommand flag
cy.prompt('Hello, world!')
cy.prompt(['Hello, world!'])
})
})
Loading