-
Notifications
You must be signed in to change notification settings - Fork 1.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
Fix #856: Be more lenient detecting window.fetch, to support polyfills. #964
Open
lincolnthree
wants to merge
1
commit into
localForage:master
Choose a base branch
from
lincolnthree:window-fetch-leniency
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm a bit worried that the entire point of checking for a native implementation was to ensure that the script's running in a browser with a native fetch because that's an indication that the given browser supports IndexedDb. This is also known as feature inference.
After we make this change, polyfilling fetch in any browser would trick localForage into thinking that IndexedDb is also supported which might not be the case.
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.
That's quite true, though that code is also a reflection of the state of JS at the time.
Out-of-scope of this PR, I think it would benefit future versions of localForage to take a more "evergreen browser" support approach and leave the 1.x branch to maintain broader compatibility. The original two selling points for localForage were compatibility and ease-of-use, but the former is much less an issue over five years after its introduction. Effectively, browsers support IndexedDB and localForage exists to work around quirks and provide a nicer API.
I think we should make this change, but I'm thinking it might be best released in a new major version.
I've been trying to focus on localForage 2.0 for some time, but other things have consistently interrupted 😅. I think I should actually have some time for it this month, so I'll see what I can do. 🙂
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.
As an alternative workaround, we could tackle this problem similar to what jQuery.noConflict did.
We could write and document a tiny JS snippet that the user of this library would need to insert before the polyfill that would set a global variable on the window and we could use the global variable in this condition.
Thoughts?
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.
My first reaction is that it sounds a bit complicated to explain, and could be a bit frustrating to implement as well. Of course, the tradeoff is it not working as-expected with a modified
fetch
, so fair enough. I'd, of course, prefer libraries weren't modifying built-infetch
, but I get why it might happen 😄I'll think about the best way to address this and try to sort out timelines for breaking changes. I'd really like to start improving the internals of localForage and modernise the library, including removing much of the older compatibility hacks/fixes and the callback support for modern JS environments. That'd be the perfect time to introduce this fix, in my opinion, so if it isn't too late it's what I'd prefer.
But if that doesn't happen soon, then we should explore shipping this fix in a non-breaking way, even if it involves a type of
noConflict
route.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.
Agreed. In our case, it's Fullstory and Sentry that both wrap the native fetch so that they can collect breadcrumbs. Not sure if there's an alternative approach so libraries will always do that.