question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$fetch using `globalThis` (not the polyfill)

See original GitHub issue

Code seems to be doing the polyfill detection, but then $fetch still uses globalThis (and not the polyfilled variable; Pv in this case.)

This is macOs high sierra, safari 11 using a prod nuxt3 build (using browserstack to test)

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
peteromanocommented, Feb 26, 2022

@pi0 I’m not adding a polyfill, im referring to the globalThis polyfill (or shim?), which is right in the ohmyfetch codebase, and that’s cool, but one place uses the globalThis shim, but another place doesn’t:

This line ends up in the nuxt3 build: https://github.com/unjs/ohmyfetch/blob/4b74e45f9989a993e725e7fe4d2e098442e457f1/src/undici.ts#L7

Browsers that dont support globalThis will just fail on that. But this: https://github.com/unjs/ohmyfetch/blob/4b74e45f9989a993e725e7fe4d2e098442e457f1/src/index.ts#L6-L14 uses the polyfill/shim.

So should the following also use the polyfill (basically _globalThis vs globalThis; and move the shim to some shared util file)? https://github.com/unjs/ohmyfetch/blob/4b74e45f9989a993e725e7fe4d2e098442e457f1/src/undici.ts#L7

0reactions
peteromanocommented, Feb 27, 2022

I was gonna say, it might not even necessarily be that the polyfill is needed, but that that part of the code shouldn’t be part of the client build in general (maybe that’s the issue?) The undici path is leaking into the client build but shouldnt be?

Maybe a boilerplate stackblitz of nuxt3 would repro the issue…

Safari 11.1.2

It’s not urgent, but like I said, it would cool for nuxt and my app to possibly be able to work on a few other browsers if this issue gets fixed; who konws, maybe this is the only issue on this safari version and everything ends up working fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node-fetch should provide a polyfill entrypoint · Issue #1317
using a library that expects fetch available as a global; working with an ... This is a polyfill for node , not for...
Read more >
A horrifying globalThis polyfill in universal JavaScript
This write-up describes the difficulties with writing a proper globalThis polyfill. Such a polyfill has the following requirements:.
Read more >
What is globalThis, and why should you start using it?
The globalThis proposal, now in stage 4, aims to consolidate the increasingly fragmented ways of accessing the global object in JavaScript.
Read more >
globalThis and Polyfill in Javascript | by Susanne Lundkvist
In web development, a polyfill is code that implements a feature on web browsers that do not support the feature. Polyfills allow web...
Read more >
globalThis - JavaScript - MDN Web Docs
With globalThis available, the additional search for the global across environments is not necessary anymore: if (typeof globalThis.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found