• Robert Knight's avatar
    Handle sidebar iframe reloads more gracefully · fcf87072
    Robert Knight authored
    If the `<hypothesis-sidebar>` element is moved around in the DOM, this can cause
    the sidebar to reload. There may also be other causes of the sidebar reloading
    (eg. process crash for out-of-process iframe?). If the sidebar loads a second
    time, it will fail to connect to the host frame since `PortProvider` will try to
    re-use the `MessageChannel` it has already allocated, but sending that channels
    ports will fail since they have already been transferred.
    
    Recovering from this scenario fully involves a lot of changes since all the
    places that have a connection to the sidebar would need to support replacing
    that channel. Also various state in host/guest frames (eg. currently loaded
    annotations) will be out of sync and need resetting.
    
    What this commit does is just to handle the situation more gracefully, by
    logging a meaningful error in the console and, after a delay, showing an error
    message in the sidebar telling the user to reload the page. This also avoids
    spamming Sentry [1] with errors about a situation that is out of our control. We
    get a lot of error reports about this each month, mainly from certain
    high-traffic pages that embed the client, but so far no actual complaints from
    users about Hypothesis not working. Therefore it doesn't yet seem valuable
    enough to do all the work to recover from a sidebar frame reload automatically.
    
    [1] https://hypothesis.sentry.io/issues/2975780063/
    fcf87072
Name
Last commit
Last update
..
components Loading commit data...
config Loading commit data...
helpers Loading commit data...
services Loading commit data...
store Loading commit data...
test Loading commit data...
util Loading commit data...
cross-origin-rpc.ts Loading commit data...
index.tsx Loading commit data...
markdown-commands.ts Loading commit data...
media-embedder.ts Loading commit data...
render-markdown.ts Loading commit data...
search-client.ts Loading commit data...
service-context.tsx Loading commit data...
websocket.ts Loading commit data...