Skip to content

Conversation

@eastlondoner
Copy link

@eastlondoner eastlondoner commented Oct 19, 2025

This fixes weird and annoying issues that can arise if vite decides to bundle the agents import multiple times.

FYI I'd also recommend adding react to this array as well but keeping the change very specific.

This addresses this issue #570

@changeset-bot
Copy link

changeset-bot bot commented Oct 19, 2025

⚠️ No Changeset found

Latest commit: bbc011c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 19, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@574

commit: bbc011c

@threepointone
Copy link
Contributor

There needs to be a better solution here, we can't expect our users to do this in all their apps. Seems like something funny going on with vite

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soft blocking

@eastlondoner
Copy link
Author

yeah you're totally right.

I really don't know the ins and outs of vite bundling tbh. For sure you can wait and see if other people run into this (seems to me it's things like monorepos, packages declaring agents as a dependency that will cause it).

I think if you want to do something about it the nice thing to do is to handle it inside of the cloudflare vite plugin

@eastlondoner
Copy link
Author

or see if there's an alternative to using that module-singleton asyncLocalStorage - although I don't know what that would be

@eastlondoner
Copy link
Author

For example If the async local storage instance was attached to the cloudflare:workers virtual module or something inside it like Cloudflare env then it would be a true singleton regardless of module resolution.

I think you can also do stuff with global which is fine but kinda yucky and leaks more

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.

2 participants