Skip to content

Commit 05b3542

Browse files
committed
correctly SSR translate attribute
1 parent 96d82b0 commit 05b3542

File tree

1 file changed

+15
-1
lines changed
  • packages/svelte/src/internal/server

1 file changed

+15
-1
lines changed

packages/svelte/src/internal/server/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ export function head(payload, fn) {
147147
head_payload.out += BLOCK_CLOSE;
148148
}
149149

150+
/**
151+
* `<div translate={false}>` should be rendered as `<div translate="no">` and _not_
152+
* `<div translate="false">`, which is equivalent to `<div translate="yes">`. There
153+
* may be other odd cases that need to be added to this list in future
154+
* @type {Record<string, Map<any, string>>}
155+
*/
156+
const replacements = {
157+
translate: new Map([
158+
[true, 'yes'],
159+
[false, 'no']
160+
])
161+
};
162+
150163
/**
151164
* @template V
152165
* @param {string} name
@@ -156,7 +169,8 @@ export function head(payload, fn) {
156169
*/
157170
export function attr(name, value, is_boolean = false) {
158171
if (value == null || (!value && is_boolean) || (value === '' && name === 'class')) return '';
159-
const assignment = is_boolean ? '' : `="${escape_html(value, true)}"`;
172+
const normalized = (name in replacements && replacements[name].get(value)) || value;
173+
const assignment = is_boolean ? '' : `="${escape_html(normalized, true)}"`;
160174
return ` ${name}${assignment}`;
161175
}
162176

0 commit comments

Comments
 (0)