Skip to content

Conversation

@SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Mar 8, 2024

Title

fix: config loading on subdomains waits for updated config

Description

Minor updates to #89

Addresses the issue brought up in #89:

Config passing between origins needs to be more carefully tested. It seems like in some cases this is not working properly, e.g. when auto-reload is set up and there isn't enough time for the message to be passed from the root to the subdomain origin.

Notes & open questions

  • uses event.waitUntil to ensure that verifiedFetch is set properly before executing requests
  • uses commsChannel.messageAndWaitForResponse to ensure that SW is ready to handle requests before executing them

Demo

2024-03-07.at.18.17.23.-.Plum.Anglerfish.mp4

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

SgtPooki added 2 commits March 8, 2024 11:43
the activate event is fired when the service worker is first activated,
and then the channel.onmessagefrom event listener is set up.
by the time the channel receives any messages, the event passed to activate
will be done, and waitUntil has no effect (and throws an error)
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

@SgtPooki SgtPooki requested a review from 2color March 8, 2024 21:57
Comment on lines +74 to +75
debugLib.enable(config.debug ?? '') // set debug level first.
log('config-debug: setting config %O for domain %s', config, window.location.origin)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set debug level before calling log method so debug level is taken into consideration immediately.

await setConfig(config)
// TODO: use channel.messageAndWaitForResponse to ensure that the config is loaded before proceeding.
channel.postMessage({ target: 'SW', action: 'RELOAD_CONFIG' })
// TODO: show spinner / disable buttons while waiting for response
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

things happen pretty fast so i don't think we want a spinner or other things, but maybe?

Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review of some more minor improvements and manual config update verification

@SgtPooki SgtPooki merged commit e652e06 into refactor-for-cache Mar 8, 2024
@SgtPooki SgtPooki deleted the fix/refactor-for-cache branch March 8, 2024 22:44
SgtPooki added a commit that referenced this pull request Mar 9, 2024
* refactor: remove unused helia andu se verified fetch

* chore: remove empty line

* fix: load config iframe using a hash fragment

fixes #88

* fix: load default config initially

* chore: fix linting errors

* chore: remove unused deps

* chore: re-add needed @helia/ipns dependency

* fix: set verifiedFetch when sw is activated

* chore: remove lib/heliaFetch and cleanup sw.ts (#95)

* fix: config loading on subdomains waits for updated config (#94)

* fix: config loading on subdomains waits for updated config

* fix: remove event.waitUtil inside channel.onmessagefrom

the activate event is fired when the service worker is first activated,
and then the channel.onmessagefrom event listener is set up.
by the time the channel receives any messages, the event passed to activate
will be done, and waitUntil has no effect (and throws an error)

* fix: service worker handles being disposed of

* fix: preload request from redirect page is handled by sw

* chore: better trace logging for config updates

---------

Co-authored-by: Daniel N <[email protected]>
Co-authored-by: Russell Dempsey <[email protected]>
@2color
Copy link
Member

2color commented Mar 9, 2024

Great stuff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants