Skip to content

Commit

Permalink
fix: ellipsis with maxWidth (#542)
Browse files Browse the repository at this point in the history
### Description
This may be a temporary fix, I didn't dig deep into yoga. But when the
return value of width here doesn't change (assuming the value of width
is 216.9), when we later get the width through
`parent.getComputedWidth()`, sometimes it returns 216 and sometimes 217.
I'm not sure if this is a yoga bug, but it seems related to the entire
page width.

Closes: #540


https://github.com/vercel/satori/assets/22126563/6929db4c-60e8-4a85-ae8b-497ad64c317e
  • Loading branch information
LuciNyan authored Sep 17, 2023
1 parent c47e1a9 commit fcaae1d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,15 @@ export default async function* buildTextNodes(
}
flow(r)
measuredTextSize = { width: r, height }
return { width: r, height }
return { width: Math.ceil(r), height }
}

measuredTextSize = { width, height }
return { width, height }
// This may be a temporary fix, I didn't dig deep into yoga.
// But when the return value of width here doesn't change (assuming the value of width is 216.9),
// when we later get the width through `parent.getComputedWidth()`, sometimes it returns 216 and sometimes 217.
// I'm not sure if this is a yoga bug, but it seems related to the entire page width.
// So I use Math.ceil.
return { width: Math.ceil(width), height }
})

const [x, y] = yield
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe('Basic', () => {
display: 'flex',
height: '100%',
width: '100%',
background: 'white',
}}
>
Hi {0} <div>hi</div> {0} {false} {undefined} {0} {null} {0} {true} {'x'}{' '}
Expand Down
2 changes: 1 addition & 1 deletion test/event.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Event', () => {
"textContent": "World",
"top": 0,
"type": "div",
"width": 41,
"width": 42,
},
]
`)
Expand Down

1 comment on commit fcaae1d

@vercel
Copy link

@vercel vercel bot commented on fcaae1d Sep 17, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.