fix(cloudflare): Json() bindings deploy as native types instead of strings - #1451
Merged
Conversation
…ts native types The Cloudflare API expects the raw JSON value in the `json` field of a json binding (as wrangler sends it). Stringifying it first made the runtime inject a JSON *string* (e.g. "false") instead of the native value (false), diverging from local dev where miniflare received the raw value. Fixes #1450 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
commit: |
The Artifacts service now returns account-scoped remote URLs (https://<account-hash>.artifacts.cloudflare.net/git/<ns>/<repo>.git) and ARTIFACTS.get() returns a JS-RPC repo handle whose metadata is exposed via info() rather than as plain data properties. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1450
Problem
Json(value)bindings behaved differently between local dev and production:env.IS_DEVELOPMENTwas a nativeboolean.prepareWorkerMetadatacalledJSON.stringify(binding.json)before sending the binding to the Cloudflare API, so the runtime injected the JSON string ("false") instead of the native value (false). SinceBoolean("false") === true, this silently broke conditional checks in production.Fix
Send the raw value in the
jsonfield of the worker metadata binding, exactly as wrangler does (wrangler converts non-stringvarsto{ type: "json", name, json: value }with the raw parsed value — seecreate-worker-upload-form.ts). The whole metadata object isJSON.stringify-ed once when appended to the upload form, so the value serializes correctly without double encoding.Also updated
WorkerBindingJson.jsonfromstringtounknownto match.Usage
Test
Added
"json bindings are injected as native types"toworker.test.ts: deploys a worker with boolean, number, and objectJsonbindings and asserts the deployed worker observes the native types (typeof env.IS_DEV === "boolean", etc.) via its workers.dev URL.🤖 Generated with Claude Code