fix: include uuid in iframe communicator logger

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-09-28 15:40:16 +02:00
parent 865e127d16
commit d5455f7c33
5 changed files with 27 additions and 12 deletions

View file

@ -43,7 +43,8 @@ export const useForceRenderPageUrlOnIframeLoadCallback = (
redirectionInProgress.current = false
log.debug('Redirect complete')
} else {
log.warn(`Navigated away from unknown URL. Forcing back to ${forcedUrl}`)
const oldUrl = frame.src === '' ? '(none)' : frame.src
log.warn(`Navigated away from unknown URL. Was ${oldUrl}. Forcing back to ${forcedUrl}`)
onNavigateAway?.()
redirectionInProgress.current = true
frame.src = forcedUrl

View file

@ -37,8 +37,6 @@ export interface RendererIframeProps extends Omit<CommonMarkdownRendererProps &
showWaitSpinner?: boolean
}
const log = new Logger('RendererIframe')
/**
* Renders the iframe for the HTML-rendering of the markdown content.
* The iframe is enhanced by the {@link useEditorToRendererCommunicator iframe communicator} which is used for
@ -69,18 +67,34 @@ export const RendererIframe: React.FC<RendererIframeProps> = ({
const [rendererReady, setRendererReady] = useState<boolean>(false)
const frameReference = useRef<HTMLIFrameElement>(null)
const iframeCommunicator = useEditorToRendererCommunicator()
const log = useMemo(() => new Logger(`RendererIframe[${iframeCommunicator.getUuid()}]`), [iframeCommunicator])
const resetRendererReady = useCallback(() => {
log.debug('Reset render status')
setRendererReady(false)
}, [])
}, [log])
const onIframeLoad = useForceRenderPageUrlOnIframeLoadCallback(frameReference, resetRendererReady)
const [frameHeight, setFrameHeight] = useState<number>(0)
useEffect(() => {
if (rendererReady) {
log.info('Renderer Ready!')
} else {
log.info('Renderer not ready')
}
}, [log, rendererReady])
useEffect(() => {
onRendererStatusChange?.(rendererReady)
}, [onRendererStatusChange, rendererReady])
useEffect(() => () => setRendererReady(false), [iframeCommunicator])
useEffect(
() => () => {
log.debug('Component ended')
setRendererReady(false)
},
[iframeCommunicator, log]
)
useEffect(() => {
if (!rendererReady) {
@ -138,7 +152,7 @@ export const RendererIframe: React.FC<RendererIframeProps> = ({
}
})
setRendererReady(true)
}, [iframeCommunicator, rendererType])
}, [iframeCommunicator, log, rendererType])
)
useEffectOnRenderTypeChange(rendererType, onIframeLoad)

View file

@ -19,7 +19,7 @@ export class EditorToRendererCommunicator extends WindowPostMessageCommunicator<
EditorToRendererMessageType,
CommunicationMessages
> {
protected createLogger(): Logger {
return new Logger('EditorToRendererCommunicator')
protected createLogger(uuid: string): Logger {
return new Logger(`EditorToRendererCommunicator[${uuid}]`)
}
}

View file

@ -19,7 +19,7 @@ export class RendererToEditorCommunicator extends WindowPostMessageCommunicator<
RendererToEditorMessageType,
CommunicationMessages
> {
protected createLogger(): Logger {
return new Logger('RendererToEditorCommunicator')
protected createLogger(uuid: string): Logger {
return new Logger(`RendererToEditorCommunicator[${uuid}]`)
}
}

View file

@ -45,14 +45,14 @@ export abstract class WindowPostMessageCommunicator<
) {
this.boundListener = this.handleEvent.bind(this)
this.communicationEnabled = false
this.log = this.createLogger()
this.log = this.createLogger(uuid)
}
public getUuid(): string {
return this.uuid
}
protected abstract createLogger(): Logger
protected abstract createLogger(uuid: string): Logger
/**
* Registers the event listener on the current global {@link window}.