Anonymous
Детское окно окна. Не возвращаясь к базовой памяти родителя
Сообщение
Anonymous » 25 сен 2025, 10:46
I Have a app in app we have a widget we want to open this widget into new window
when i open window i communicate to parent window open in child when child is closed i communicate to parent child closed so parent open this widget in parent
problem is when i open it Требуется много памяти, чтобы открыть
I Исследование по этому поводу, и люди говорят, что это требует
, поэтому, когда я закрываю виджет, он должен вернуться к базовой памяти < /p>
Код: Выделить всё
export const openWidgetInNewWindow = ({
widgetId,
rowData,
width = 900,
height = 600,
data,
onCloseCallback = null,
}) => {
// Get the name of the widget based on the ID
const widgetName = Object.keys(allWidgetIDs).find(
(key) => allWidgetIDs[key]?.id === widgetId,
)
// Calculate center position for the child window
const left = window.screenX + (window.outerWidth - width) / 2
const top = window.screenY + (window.outerHeight - height) / 2
const url = `/widget/${widgetId}/${widgetName}`
// Open the child window with specified dimensions and position
childWindow = window.open(
url,
'_blank',
`width=${width},height=${height},top=${top},left=${left}`,
)
// Store the window reference using its ID
openWindows[widgetId] = childWindow
if (childWindow) {
childWindow.focus()
// Set the widget as open in Redux
store.dispatch.boards.addWidget({
boardId: rowData,
widget: { id: widgetId, name: widgetName },
childOpen: true,
})
// Getting the latest current Board after dispatching so that can be used throughout the app
const updatedCurrentBoard = getCurrentBoard()
// Event handler to handle messages from child window (like closure)
const closeTimeouts = {}
const handleMessage = (event) => {
if (event.data?.type === 'childClosed') {
const widgetId = event?.data?.widgetId
const data = event.data?.closed
if (closeTimeouts[widgetId]) {
clearTimeout(closeTimeouts[widgetId])
}
closeTimeouts[widgetId] = setTimeout(() => {
if (data) {
updateWidgetChildOpen(widgetId, false)
if (onCloseCallback) onCloseCallback()
}
delete closeTimeouts[widgetId]
}, 10)
}
}
// Listen for messages from the child window
window.addEventListener('message', handleMessage)
// Cleanup listener on component unmount
const cleanup = () => {
window.removeEventListener('message', handleMessage)
}
window.reduxStore = updatedCurrentBoard
return { childWindow, cleanup }
} else {
console.error('Failed to open child window')
return null
}
}
< /code>
Это детское окно < /p>
function OrderEntry(props) {
const { defaultSettings, widgetId, rowData } = props
const boardId = rowData
return (
openWidgetInNewWindow({
widgetId,
rowData: boardId,
width: 346,
height: 400,
onCloseCallback: () => {
console.log('Widget closed')
},
})
}
>
Childwindow open
)
}
OrderEntry.propTypes = {
defaultSettings: propTypes.object.isRequired,
widgetId: propTypes.any,
rowData: propTypes.string,
}
export default memo(OrderEntry)
useEffect(() => {
// Initialize global event listeners
console.log('Initializing global event listeners')
const cleanupFns = initializeGlobalEventListeners({
messageHandler: (event) => handleWidgetCommunication(event),
unloadHandler: () => console.log('Window unloaded'),
widgetId: widgetId,
})
// Apply zoom reset
function applyZoomReset() {
const r = window.devicePixelRatio || 1
document.documentElement.style.zoom = 1 / r
}
window.addEventListener('resize', applyZoomReset)
applyZoomReset()
// Cleanup both on unmount
return () => {
cleanupFns.forEach((cleanupFn) => cleanupFn())
window.removeEventListener('resize', applyZoomReset)
}
}, [])
Подробнее здесь:
https://stackoverflow.com/questions/797 ... -of-parent
1758786360
Anonymous
I Have a app in app we have a widget we want to open this widget into new window when i open window i communicate to parent window open in child when child is closed i communicate to parent child closed so parent open this widget in parent [img]https://i.sstatic.net/fwNFVo6t.png[/img] problem is when i open it Требуется много памяти, чтобы открыть I Исследование по этому поводу, и люди говорят, что это требует , поэтому, когда я закрываю виджет, он должен вернуться к базовой памяти < /p> [code]export const openWidgetInNewWindow = ({ widgetId, rowData, width = 900, height = 600, data, onCloseCallback = null, }) => { // Get the name of the widget based on the ID const widgetName = Object.keys(allWidgetIDs).find( (key) => allWidgetIDs[key]?.id === widgetId, ) // Calculate center position for the child window const left = window.screenX + (window.outerWidth - width) / 2 const top = window.screenY + (window.outerHeight - height) / 2 const url = `/widget/${widgetId}/${widgetName}` // Open the child window with specified dimensions and position childWindow = window.open( url, '_blank', `width=${width},height=${height},top=${top},left=${left}`, ) // Store the window reference using its ID openWindows[widgetId] = childWindow if (childWindow) { childWindow.focus() // Set the widget as open in Redux store.dispatch.boards.addWidget({ boardId: rowData, widget: { id: widgetId, name: widgetName }, childOpen: true, }) // Getting the latest current Board after dispatching so that can be used throughout the app const updatedCurrentBoard = getCurrentBoard() // Event handler to handle messages from child window (like closure) const closeTimeouts = {} const handleMessage = (event) => { if (event.data?.type === 'childClosed') { const widgetId = event?.data?.widgetId const data = event.data?.closed if (closeTimeouts[widgetId]) { clearTimeout(closeTimeouts[widgetId]) } closeTimeouts[widgetId] = setTimeout(() => { if (data) { updateWidgetChildOpen(widgetId, false) if (onCloseCallback) onCloseCallback() } delete closeTimeouts[widgetId] }, 10) } } // Listen for messages from the child window window.addEventListener('message', handleMessage) // Cleanup listener on component unmount const cleanup = () => { window.removeEventListener('message', handleMessage) } window.reduxStore = updatedCurrentBoard return { childWindow, cleanup } } else { console.error('Failed to open child window') return null } } < /code> Это детское окно < /p> function OrderEntry(props) { const { defaultSettings, widgetId, rowData } = props const boardId = rowData return ( openWidgetInNewWindow({ widgetId, rowData: boardId, width: 346, height: 400, onCloseCallback: () => { console.log('Widget closed') }, }) } > Childwindow open ) } OrderEntry.propTypes = { defaultSettings: propTypes.object.isRequired, widgetId: propTypes.any, rowData: propTypes.string, } export default memo(OrderEntry) useEffect(() => { // Initialize global event listeners console.log('Initializing global event listeners') const cleanupFns = initializeGlobalEventListeners({ messageHandler: (event) => handleWidgetCommunication(event), unloadHandler: () => console.log('Window unloaded'), widgetId: widgetId, }) // Apply zoom reset function applyZoomReset() { const r = window.devicePixelRatio || 1 document.documentElement.style.zoom = 1 / r } window.addEventListener('resize', applyZoomReset) applyZoomReset() // Cleanup both on unmount return () => { cleanupFns.forEach((cleanupFn) => cleanupFn()) window.removeEventListener('resize', applyZoomReset) } [/code] }, []) Подробнее здесь: [url]https://stackoverflow.com/questions/79774521/child-window-window-open-not-returning-to-the-base-memory-of-parent[/url]