Skip to content

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Oct 3, 2025

Fixes #10855

Astro detects Node with:

const isNode = typeof process !== "undefined" && Object.prototype.toString.call(process) === "[object process]";

With unenv process would toString as [object Object] and isNode is false.
The the v2 implementation from @guybedford it toString as [object process] to match the Node implementation (this is correct) so isNode becomes true

However, when Node is detected, Astro construct a response from an AsyncIterable:

  if (streaming) {
    if (isNode && !isDeno) {
      const nodeBody = await renderToAsyncIterable(
        result,
        componentFactory,
        props,
        children,
        true,
        route
      );
      body = nodeBody;
    } else {
      body = await renderToReadableStream(result, componentFactory, props, children, true, route);
    }
  } else {
    body = await renderToString(result, componentFactory, props, children, true, route);
  }

But we know that workerd behavior does not conform to Node here, see cloudflare/workerd#2746. Fixing that issue would solve the Astro issue (i.e. we could drop the process polyfill).

However we will revert the PR dropping the polyfill for now.

Notes:

  • It looks like sentry is also using the same isNode check - we should inspect commonly used packages before dropping the process polyfill again.

  • There are a couples of additional changes on top of the revert:

    • the workerd dependency in unenv is bump to 0927 when the behavior of the builtin process.toString was updated
    • the latest version of the tests is used are they are more correct than the version before the PR.

  • Tests
    • Tests included
    • Tests not necessary because: already tests, tested Astro locally
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: not behavior change
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: unenv changes not backported

@vicb vicb requested review from a team as code owners October 3, 2025 09:05
Copy link

changeset-bot bot commented Oct 3, 2025

🦋 Changeset detected

Latest commit: 9a6f7f0

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

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

@vicb
Copy link
Contributor Author

vicb commented Oct 3, 2025

/cc @jasnell @anonrig @danlapid

Copy link

pkg-pr-new bot commented Oct 3, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@10860

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@10860

miniflare

npm i https://pkg.pr.new/miniflare@10860

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@10860

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@10860

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@10860

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@10860

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@10860

wrangler

npm i https://pkg.pr.new/wrangler@10860

commit: 9a6f7f0

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Oct 3, 2025
@edmundhung edmundhung merged commit 2594130 into main Oct 3, 2025
34 checks passed
@edmundhung edmundhung deleted the vicb/revert-10805 branch October 3, 2025 10:09
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

SSR pages and components broken in Astro when using Wrangler 4.40.3 or above
3 participants