Skip to content

Commit

Permalink
polishing after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskus committed Apr 23, 2021
1 parent e7e1e8f commit 3b37d15
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions catalog/app/components/Preview/loaders/Notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from 'react'
import * as AWS from 'utils/AWS'
import * as Data from 'utils/Data'
import * as Config from 'utils/Config'
import mkSearch from 'utils/mkSearch'

import { PreviewData } from '../types'
import * as utils from './utils'
Expand All @@ -24,10 +25,10 @@ function NotebookLoader({ handle, children }) {
}

const IFRAME_SANDBOX_ATTRIBUTES = 'allow-scripts allow-same-origin'
const IFRAME_LOAD_TIMEOUT = 30000

function waitForIframe(src) {
let resolved = false
const timeout = 30000

return new Promise((resolve, reject) => {
const handleError = (error) => {
Expand All @@ -44,7 +45,7 @@ function waitForIframe(src) {
const timerId = setTimeout(() => {
if (resolved) return
handleError(new Error('Page is loading too long'))
}, timeout)
}, IFRAME_LOAD_TIMEOUT)

const link = document.createElement('iframe')
link.addEventListener('load', () => {
Expand All @@ -64,11 +65,7 @@ function waitForIframe(src) {
})
}

async function loadVoila({ endpoint, sign, handle }) {
const base = `${endpoint}/voila/voila/render`
const url = encodeURIComponent(sign(handle))
const src = `${base}/?url=${url}`

async function loadVoila({ src }) {
// Preload iframe, then insert cached iframe
await waitForIframe(src)
return PreviewData.IFrame({ src, sandbox: IFRAME_SANDBOX_ATTRIBUTES })
Expand All @@ -77,7 +74,8 @@ async function loadVoila({ endpoint, sign, handle }) {
function VoilaLoader({ handle, children }) {
const sign = AWS.Signer.useS3Signer()
const endpoint = Config.use().registryUrl
const data = Data.use(loadVoila, { endpoint, sign, handle })
const src = `${endpoint}/voila/voila/render/${mkSearch({ url: sign(handle) })}`

This comment has been minimized.

Copy link
@nl0

nl0 Apr 24, 2021

Member

this should be memoized, bc sign() will give you a new url on every invocation

This comment has been minimized.

Copy link
@nl0

nl0 Apr 24, 2021

Member

i see that you fixed that already

const data = Data.use(loadVoila, { src })
return children(utils.useErrorHandling(data.result, { handle, retry: data.fetch }))
}

Expand Down

0 comments on commit 3b37d15

Please sign in to comment.