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.

Compatibility with server-side Web API runtimes: Next.js Edge Runtime, Deno, Cloudflare Workers / Pages.

See original GitHub issue

The problem

Next.js recently released Edge Runtime in version 12.2 as an experimental feature, this includes doing serverside rendering on the edge in a different runtime than Node.js. It’s a runtime similar to Deno and Cloudflare Workers / Pages, they’re built on the v8 browser engine, for the server.

I’ve experimented with running the with-emotion-swc-app example with the Experimental Edge runtime enabled, which initially caused the following issue:

error - node_modules/.pnpm/@emotion+cache@11.9.3/node_modules/@emotion/cache/dist/emotion-cache.browser.esm.js (245:0) @ <unknown>
ReferenceError: document is not defined

The compiler/bundler loads by default the .browser version of the build output of @chakra-ui/cache, this output doesn’t have the isBrowser checks that the regular outputs have (since it assumes it’s already in the browser). This was initially fixed for me locally when I manually replaced the .browser.esm.js file with the regular .esm.js file.

Proposed solution

  • Add isBrowser checks to browser bundles
  • Check for available Web API alternatives instead of node APIs, if available use those in all @emotion packages.

Supporting these runtimes would greatly benefit the ecosystem and allow users of Emotion, and everything built on top of it, to use Emotion in newer runtimes and frameworks like Deno (Fresh), Next.js Edge Runtime, and Cloudflare Workers.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:8
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Aug 16, 2022

There are some new APIs~ coming to React in the future. In the face of those possibilities, I’m not sure if it’s worth working on a custom streaming solution: https://twitter.com/joshcstory/status/1559482199388426240

Maybe we could work on a custom stream transformer, but I would be hesitant to add any code to Emotion itself (I mean our components etc) to support this.

1reaction
ItsWendellcommented, Jun 30, 2022

@srmagura that’s amazing, the Next.js Edge Runtime is actually confirmed to be built on Cloudflare Workers (at this time). So both should work here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

And here's another one: the Next.js Edge Runtime becomes ...
Deploy your Next.js app to Cloudflare Pages ... Let's walk through an example, creating a new Next.js application that opts into this Edge...
Read more >
Netlify Edge Functions: A new serverless runtime powered by ...
While the general trend today is to back the serverless environment with Javascript runtimes (Cloudflare runs its edge on top of V8, Netlify...
Read more >
The Cloudflare Stack: The Performant, Cost-Effective, Zero ...
A screenshot of the product page for Cloudflare Workers with a header ... The rise of Web Platform API-based runtimes like Deno and...
Read more >
Worker Runtimes | The new standard for web servers - JS.ORG
Since originally writing this, both Deno and Cloudflare Workers have dropped support for the pattern shown above. While the Request and Response classes...
Read more >
Blog | Deno
Deno 1.26 adds Cache Web API; improves permission system, experimental npm support, Node.js compatibility; ships with TypeScript 4.8, and more.
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