Skip to content
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

New cacheWriteDidFail lifecycle callback #1530

Closed
jeffposnick opened this issue Jun 13, 2018 · 14 comments
Closed

New cacheWriteDidFail lifecycle callback #1530

jeffposnick opened this issue Jun 13, 2018 · 14 comments

Comments

@jeffposnick
Copy link
Contributor

Library Affected:
workbox-core

Moved from #1505 (comment)

@philipwalton writes:

Yeah, I get the intention of the change, I'm just wondering if it could be somehow better integrated into the rest of workbox.

Did you consider creating a new lifecycle callback: maybe something like cacheWriteDidFail? And in the same way that we can register a generic fetch failure handler, we could register generic cache failure handler.

Anyway, I don't want to block this feature being added, especially if we know folks are running into quota issues today. And you've obviously thought about the trade-offs, so I'm happy with whatever you think is best.

But I think we should revisit it later. I also think it's probably worth adding a catchWriteDidFail lifecycle method at some point regardless, so strategy plugin authors can handle these cases individually without potentially affecting plugins they don't own.

@jeffposnick
Copy link
Contributor Author

I think we can get this in for v6 as part of the overall lifecycle overhaul.

@jeffposnick jeffposnick added this to the v6 milestone Apr 28, 2020
@jeffposnick jeffposnick removed this from the v6 milestone Dec 2, 2020
@jeffposnick jeffposnick added the Good First Issue This would be an ideal issue for a new contributor to take on. label Mar 12, 2021
@srikanthavadhanula
Copy link

Hi @jeffposnick,
I am new to open source contribution, wanted to pick this issue, as it is labeled "Good First Issue" for beginners
I am going through the developer page: https://developers.google.com/web/tools/workbox/
Can you please provide me a heads-up on where to start?

Thanks

@jeffposnick
Copy link
Contributor Author

Hello @srikanthavadhanula! Thanks so much for the interest in contributing to Workbox!

The portion of the codebase that's related to this issue is

try {
await cache.put(effectiveRequest, hasCacheUpdateCallback ?
responseToCache.clone() : responseToCache);
} catch (error) {
if (error instanceof Error) {
// See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError
if (error.name === 'QuotaExceededError') {
await executeQuotaErrorCallbacks();
}
throw error;
}
}

Before the throw error; statement on line 370, the code would need to do something similar to what's going on in this piece of code:

for (const callback of this.iterateCallbacks('cacheDidUpdate')) {
await callback({
cacheName,
oldResponse,
newResponse: responseToCache.clone(),
request: effectiveRequest,
event: this.event,
});
}

That code iterates over cacheDidUpdate callbacks, but this new code would check for callbacks named cacheWriteDidFail, and iterate over those. I think the callback would take a similar set of parameters, excluding oldResponse.

The other piece of the puzzle would be to update https://github.com/GoogleChrome/workbox/blob/8c49eb93d9a11431fc981f0d297247ca9484b003/packages/workbox-core/src/types.ts to include information about the new callback type and parameters that it takes.

...and then the other, other piece of the puzzle would be to update the test suite in https://github.com/GoogleChrome/workbox/blob/8c49eb93d9a11431fc981f0d297247ca9484b003/test/workbox-strategies/sw/test-StrategyHandler.mjs to exercise the new callback.

There's obviously a lot of different pieces there, and we're happy to walk you through any of those specific sub-steps if you get stuck along the way. Given all that, let us know your level of comfort taking this on.

@srikanthavadhanula
Copy link

Thanks @jeffposnick
This gave me a good amount of understanding of what changes need to be done.
I have forked the code, trying to run locally the code and test suite.
changes seem straightforward, I am trying to understand how test cases were written for existing scenarios like (cacheDidUpdate)

@jeffposnick
Copy link
Contributor Author

That's great—if you run into any specific problems that are blocking you, please let us know!

@bonsai-rishabh
Copy link

If this issue has not been resolved yet I would love to help out if possible.

@jeffposnick
Copy link
Contributor Author

@srikanthavadhanula, is this still something you'd want to take on?

@ghost
Copy link

ghost commented Dec 7, 2021

@jeffposnick if this hasn't been resolved, I'd love to help out!

@jeffposnick
Copy link
Contributor Author

Thanks, @evanrittenhouse—it doesn't sound like @srikanthavadhanula is able to help at the moment, so we would appreciate your contribution!

@jeffposnick jeffposnick assigned ghost and unassigned srikanthavadhanula Dec 7, 2021
@jeffposnick
Copy link
Contributor Author

(There's information about getting set up to make contributions and run the build/test suite at https://github.com/GoogleChrome/workbox/blob/v6/CONTRIBUTING.md)

@ghost
Copy link

ghost commented Dec 9, 2021

@jeffposnick I was reading the above comment chain to try to figure out what needs to happen, but can't seem to understand - do we only need to iterate over (const callback of this.iterateCallbacks('cacheDidFail'))'? Is there a cacheDidFail callback that I need to write?

Sorry - this is my first open-source contribution (saw that it's marked as a good first issue) and am a little unclear on how to start. Any guidance/help would be much appreciated. Thank you!

@jeffposnick
Copy link
Contributor Author

Hello @evanrittenhouse—no worries. I'm starting to wonder if marking this as a "good first issue" has ended up misleading folks, given that others have also had issues implementing it.

There is currently no cacheDidFail callback, so closing out this issue would involve creating TypeScript definitions for it and then calling any registered callbacks at the appropriate place in the codebase, getting them via this.iterateCallbacks('cacheDidFail'). And then adding in tests to ensure that it works.

We can also just assign someone from the core team to work on this if you're stuck—again, it's probably more involved than a lot of "good first issue"s would ideally be.

@ghost
Copy link

ghost commented Dec 18, 2021

Ahh, I see @jeffposnick. Unfortunately it is probably a little bit beyond my scope - are there any other issues I can contribute to that you're aware of?

@jeffposnick jeffposnick unassigned ghost Dec 20, 2021
@jeffposnick jeffposnick removed the Good First Issue This would be an ideal issue for a new contributor to take on. label Dec 20, 2021
@tomayac
Copy link
Member

tomayac commented Apr 25, 2024

Hi there,

Workbox is moving to a new engineering team within Google. As part of this move, we're declaring a partial bug bankruptcy to allow the new team to start fresh. We realize this isn't optimal, but realistically, this is the only way we see it working. For transparency, here're the criteria we applied:

Thanks, and we hope for your understanding!
The Workbox team

@tomayac tomayac closed this as completed Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants