-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raft Snapshot Download Bug #17769
Raft Snapshot Download Bug #17769
Conversation
…e-overview component
|
||
addSuccessHandler(function (registration) { | ||
// attach the handler for the message event so we can send over the auth token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think the only issue here is that the handler in init
won't be called on the initial installation of the worker. This handler gets called when the worker is registered: https://github.com/DockYard/ember-service-worker/blob/4564e495666865b80fd29daf15784e2801b59d1b/service-worker-registration/index.js#L13 - so the check in the init
function will only be truthy on subsequent tries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering about that too. I was thinking since the event listener for the message is added when the component initializes then it would be listening before the user has a chance to click the download action 🤔.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I think you're right - I looked at the file I linked again (lol), and it runs when the JS package loads, so it should be installed by the time you get to the download page (or by the time it renders). Sorry it's been a little bit since I looked at this 😅 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks for talking through it with me! This is the first time I have looked at that part of the code and wanted to make sure I am understanding things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Just a question
const [port] = event.ports; | ||
|
||
if (action === 'getToken') { | ||
port.postMessage({ token: this.auth.currentToken }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still want to account for when/if the token isn't retrieved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like the original implementation was doing anything other than logging an error to the console. If there is no token the request would result in a 403. I'm not sure in practice if this would occur now since the user would be redirected to the auth route before the component is instantiated.
await render(hbs`<RaftStorageOverview @model={{this.model}} />`); | ||
assert.dom('[data-raft-row]').exists({ count: 2 }); | ||
}); | ||
|
||
test('it should download snapshot via service worker', async function (assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't come up with a nice way to test this end to end with the service worker in an appreciable amount of time so I added a test for the component to ensure that it's doing its part.
* moves service worker message event listener from addon to raft-storage-overview component * adds changelog entry * adds raft-storage-overview test for downloading snapshot via service worker
* moves service worker message event listener from addon to raft-storage-overview component * adds changelog entry * adds raft-storage-overview test for downloading snapshot via service worker
* moves service worker message event listener from addon to raft-storage-overview component * adds changelog entry * adds raft-storage-overview test for downloading snapshot via service worker
* moves service worker message event listener from addon to raft-storage-overview component * adds changelog entry * adds raft-storage-overview test for downloading snapshot via service worker
An uncaught error was causing the service worker to hang when attempting to download a raft snapshot which would eventually result in a permission denied response since the token was not provided to the fetch request.
In the
service-worker-authenticated-download
in-repo addon theservice-worker-registration
is attempting to import from@ember/application/namespace
. In the generatedsw-registration.js
script this results in that module being accessed from theEmber
global which has been removed and is undefined.Screencast.from.2022-11-01.03.27.11.PM.webm
This seems to be an issue with
ember-auto-import
(or babel or webpack by extension) but I just couldn't figure out how to get that import working. I decided to move the event listener to theraft-storage-overview
component in the parent application which is already doing a check for the service worker registration and where the download action lives.