Skip to content

Commit

Permalink
Apply white-space inline style when astGenerator missing
Browse files Browse the repository at this point in the history
This fixes an SSR mismatch when using a non-async SyntaxHighlighter on the server
and an async SyntaxHighlighter on the client - the whiteSpace style will be present
regardless of which return statement we hit later in the function.
  • Loading branch information
fracture91 authored and conorhastings committed Nov 15, 2021
1 parent 76d7f11 commit ddc6fbb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ export default function(defaultAstGenerator, defaultStyle) {
style: Object.assign({}, customStyle)
});

if (wrapLongLines) {
codeTagProps.style = { ...codeTagProps.style, whiteSpace: 'pre-wrap' };
} else {
codeTagProps.style = { ...codeTagProps.style, whiteSpace: 'pre' };
}

if (!astGenerator) {
return (
<PreTag {...preProps}>
Expand Down Expand Up @@ -409,12 +415,6 @@ export default function(defaultAstGenerator, defaultStyle) {
wrapLongLines
);

if (wrapLongLines) {
codeTagProps.style = { ...codeTagProps.style, whiteSpace: 'pre-wrap' };
} else {
codeTagProps.style = { ...codeTagProps.style, whiteSpace: 'pre' };
}

return (
<PreTag {...preProps}>
<CodeTag {...codeTagProps}>
Expand Down

0 comments on commit ddc6fbb

Please sign in to comment.