Skip to content

[c3] fix: ensure the Angular fetch handler returns a "real" promise to Cloudflare#3516

Merged
petebacondarwin merged 1 commit intomainfrom
c3-angular-workaround
Jun 25, 2023
Merged

[c3] fix: ensure the Angular fetch handler returns a "real" promise to Cloudflare#3516
petebacondarwin merged 1 commit intomainfrom
c3-angular-workaround

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

Angular employs the Zone.js library to patch potentially async operations so that
it can trigger change detection reliably. But in order to do this, it swaps out
the native Promise with a ZoneAwarePromise class.

The Cloudflare runtime (i.e. workerd) does runtime checks on the value returned
from the fetch() handler, expecting it to be a native Promise and fails if not.

This fix ensures that the actual object returned from the fetch() is actually a
native Promise. We don't need to stop Angular using ZoneAwarePromises elsewhere.

Fixes # [insert GH or internal issue number(s)].

What this PR solves / how to test:

Associated docs issue(s)/PR(s):

  • [insert associated docs issue(s)/PR(s)]

Author has included the following, where applicable:

Reviewer is to perform the following, as applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

…o Cloudflare

Angular employs the Zone.js library to patch potentially async operations so that
it can trigger change detection reliably. But in order to do this, it swaps out
the native `Promise` with a `ZoneAwarePromise` class.

The Cloudflare runtime (i.e. workerd) does runtime checks on the value returned
from the `fetch()` handler, expecting it to be a native `Promise` and fails if not.

This fix ensures that the actual object returned from the `fetch()` is actually a
native `Promise`. We don't need to stop Angular using `ZoneAwarePromises` elsewhere.
@petebacondarwin petebacondarwin requested review from a team, RamIdeas and jculvey as code owners June 23, 2023 13:03
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jun 23, 2023

🦋 Changeset detected

Latest commit: e15cb05

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/5356661752/npm-package-wrangler-3516

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/3516/npm-package-wrangler-3516

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/5356661752/npm-package-wrangler-3516 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/5356661752/npm-package-cloudflare-pages-shared-3516

Note that these links will no longer work once the GitHub Actions artifact expires.

@petebacondarwin petebacondarwin merged commit 941764d into main Jun 25, 2023
@petebacondarwin petebacondarwin deleted the c3-angular-workaround branch June 25, 2023 18:02
@github-actions github-actions bot mentioned this pull request Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants