Skip to content

Commit

Permalink
Merge pull request #3146 from sveltejs/gh-2135
Browse files Browse the repository at this point in the history
handle circular values when rendering bindings
  • Loading branch information
Rich-Harris authored Jul 1, 2019
2 parents 2915cf9 + 4082566 commit 1427206
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/internal/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function get_store_value<T>(store: Readable<T>): T | undefined {

export function add_attribute(name, value) {
if (!value) return '';
return ` ${name}${value === true ? '' : `=${JSON.stringify(value)}`}`;
return ` ${name}${value === true ? '' : `=${typeof value === 'string' ? JSON.stringify(value) : `"${value}"`}`}`;
}

export function add_classes(classes) {
Expand Down
13 changes: 13 additions & 0 deletions test/runtime/samples/binding-circular/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {
html: `
<select>
<option value="[object Object]">wheeee</option>
</select>
`,

ssrHtml: `
<select value="[object Object]">
<option value="[object Object]">wheeee</option>
</select>
`
};
10 changes: 10 additions & 0 deletions test/runtime/samples/binding-circular/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
let obj = {};
obj.self = obj;
let selected = obj;
</script>

<select bind:value={selected}>
<option value={obj}>wheeee</option>
</select>

0 comments on commit 1427206

Please sign in to comment.