Repository: preactjs/preact-render-to-string
Pull request #288 (2023-03-23 20:43:42)

Enumerate draggable attribute
Based on the docs, `draggable` is an enumerated attribute and not Boolean. A value of `true` or `false` is mandatory. 

https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable

Currently, `render-to-string` renders as `<img draggable />` (incorrect) instead of `<img draggable="true" />`  (correct). 


changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: 01ea470e70c039e152419f53c40f975d69a6ce0f

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.**

<details><summary>This PR includes no changesets</summary>

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

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/glenchao/preact-render-to-string/new/fixDraggableAttribute?filename=.changeset/poor-brooms-march.md&value=---%0A%22preact-render-to-string%22%3A%20patch%0A---%0A%0AEnumerate%20draggable%20attribute%0A)



Patch:
diff --git a/.changeset/fifty-hounds-press.md b/.changeset/fifty-hounds-press.md
new file mode 100644
index 0000000..ae5133b
--- /dev/null
+++ b/.changeset/fifty-hounds-press.md
@@ -0,0 +1,5 @@
+---
+"preact-render-to-string": patch
+---
+
+Enumerate draggable attribute, so the output isn't `draggable` but `draggable="true"`
diff --git a/src/index.js b/src/index.js
index a9309ec..31bae09 100644
--- a/src/index.js
+++ b/src/index.js
@@ -311,8 +311,13 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
 					name = name.toLowerCase().replace(XLINK_REPLACE_REGEX, 'xlink:');
 				} else if (UNSAFE_NAME.test(name)) {
 					continue;
-				} else if (name[0] === 'a' && name[1] === 'r' && v != null) {
-					// serialize boolean aria-xyz attribute values as strings
+				} else if (
+					((name[0] === 'a' && name[1] === 'r') || name === 'draggable') &&
+					v != null
+				) {
+					// serialize boolean aria-xyz or draggable attribute values as strings
+					// `draggable` is an enumerated attribute and not Boolean. A value of `true` or `false` is mandatory
+					// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable
 					v += '';
 				}
 			}


Test patch:
diff --git a/test/render.test.js b/test/render.test.js
index 7ab0bcf..0b501dd 100644
--- a/test/render.test.js
+++ b/test/render.test.js
@@ -135,6 +135,13 @@ describe('render', () => {
 			expect(rendered).to.equal(expected);
 		});
 
+		it('should include boolean draggable attribute', () => {
+			let rendered = render(<div draggable />),
+				expected = `<div draggable="true"></div>`;
+
+			expect(rendered).to.equal(expected);
+		});
+
 		describe('attribute name sanitization', () => {
 			it('should omit attributes with invalid names', () => {
 				let rendered = render(