Skip to content

fix(web): keep the JSON toString on responses filled with defaults - #2020

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/apply-defaults-tostring
Oct 13, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/apply-defaults-tostring

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Client.call attaches a non-enumerable toString to object responses. The { ...model.defaults, ...value } spread in fillDefaults drops it, so every response that goes through applyDefaults prints [object Object].

const preset = await general.getPreset();
preset.toString();
// before: '[object Object]'
// after:  '{"name":"guest","count":25,"enabled":false,"tier":"free"}'

Fix: when the input has its own toString, the same one is defined again on the filled result. This covers the web, node and react-native templates. Deno has no such override.

Test: the web, node and react-native e2e programs print preset toString: ... (JS_MODEL_TO_STRING_RESPONSES). WebNodeTest fails without the template change ([object Object]) and passes with it. Node20Test and ReactNativeTest pass.

Related: #2017

Client.call defines a non-enumerable toString on every object response. fillDefaults rebuilds the object with a spread, which copies only enumerable own properties, so every response routed through applyDefaults printed [object Object]. Re-define the same toString on the filled result in the web, node and react-native templates.
@hansi-codes

hansi-codes Bot commented Oct 13, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The default-fill path restores the same JSON serialization behavior attached by Client.call, and the change adds observable E2E coverage for each affected SDK.

The Web, Node, and React Native templates now preserve the JSON toString behavior when applying model defaults. E2E coverage prints the stringified default-filled preset response across those SDKs.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 10
File Change
templates/web/src/client.ts.twig Restores the JSON toString method on responses copied while applying defaults.
templates/node/src/client.ts.twig Restores the JSON toString method on responses copied while applying defaults.
templates/react-native/src/client.ts.twig Restores the JSON toString method on responses copied while applying defaults.
tests/e2e/Base.php Adds the expected output for the default-filled response's JSON string.
tests/e2e/Node18Test.php, tests/e2e/Node20Test.php, tests/e2e/Node26Test.php Includes the new JSON toString output in Node E2E expectations.
tests/e2e/ReactNativeTest.php, tests/e2e/WebChromiumTest.php, tests/e2e/WebNodeTest.php Includes the new JSON toString output in React Native and Web E2E expectations.
tests/e2e/languages/node/test.js Prints the default-filled preset's JSON string in the Node E2E program.
tests/e2e/languages/react-native/browser.js Prints the default-filled preset's JSON string in the React Native E2E program.
tests/e2e/languages/web/index.html Prints the default-filled preset's JSON string in the browser E2E program.
tests/e2e/languages/web/node.js Prints the default-filled preset's JSON string in the Web Node E2E program.

Reviewed 6197a30 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit 49bb526 into main Oct 13, 2026
61 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/apply-defaults-tostring branch October 13, 2026 11:36
@ChiragAgg5k ChiragAgg5k self-assigned this Oct 13, 2026
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.

1 participant