From f9f1dab70a6014b68ce5197544fae396340b6670 Mon Sep 17 00:00:00 2001 From: Chase Fleming Date: Wed, 7 Sep 2022 16:12:57 -0700 Subject: [PATCH] Discovery API not loading on SSR apps in Safari and Incognito (#1404) * Update authn.js Looks like page loaded before event listeners are added in Safari. Seems to be an issue with SSRs. Addresses: https://github.com/onflow/fcl-discovery/issues/106 * Add changeset Co-authored-by: Chase Fleming <1666730+chasefleming@users.noreply.github.com> --- .changeset/young-mice-bow.md | 5 +++++ packages/fcl/src/discovery/services/authn.js | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/young-mice-bow.md diff --git a/.changeset/young-mice-bow.md b/.changeset/young-mice-bow.md new file mode 100644 index 000000000..68b78dbd4 --- /dev/null +++ b/.changeset/young-mice-bow.md @@ -0,0 +1,5 @@ +--- +"@onflow/fcl": patch +--- + +Fixes issue where Discovery API was not loading for server side rendered applications on Safari or Chrome Incognito. diff --git a/packages/fcl/src/discovery/services/authn.js b/packages/fcl/src/discovery/services/authn.js index 8cd7c7dc4..be64e73dc 100644 --- a/packages/fcl/src/discovery/services/authn.js +++ b/packages/fcl/src/discovery/services/authn.js @@ -55,8 +55,12 @@ const HANDLERS = { '"fcl.discovery" is only available in the browser.' ) // If you call this before the window is loaded extensions will not be set yet - window.onload = async () => { + if (document.readyState === 'complete') { fetchServicesFromDiscovery() + } else { + window.onload = async () => { + fetchServicesFromDiscovery() + } } }, [SERVICE_ACTOR_KEYS.UPDATE_RESULTS]: (ctx, _letter, data) => {