-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1265 add support for asset tokens #1337
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
src/plugin/setValuesOnNode.ts
Outdated
if (values.asset && typeof values.asset === 'string') { | ||
if ('fills' in node && data.asset) { | ||
const imageUrl = values.asset; | ||
const newPaint = await fetch(imageUrl).then((response) => response.arrayBuffer()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work? I didn't think the Figma plugin sandbox supported sending network requests (as per https://www.figma.com/plugin-docs/making-network-requests/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/plugin/setValuesOnNode.ts
Outdated
} | ||
|
||
if (!matchingStyleId || (matchingStyleId && !(await trySetStyleId(node, 'fill', matchingStyleId)))) { | ||
setImageValuesOnTarget(node, { value: new Uint8Array(newPaint), description: data.description }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regardless we should probably not fetch the image itself until this point anyways. Because otherwise we'll be fetching the image and then setting a style (so not using the image buffer at all) - and then we're making a redundant request to the resource.
Commit SHA:35149b8dd04bd5397effce1ecac602def945c7e7 Test coverage results 🧪
|
Commit SHA:cf92b6852e98fdbd57cc7b28a49ba92d98a9a0d2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@six7 I'm wondering a little bit here what the actual behavior should be as to the combination of styles and assets. We can't really match on anything to find an existing style because the byte objects will always be different and the paint will have no reference as to what the image source is. I think we will just need to forego any style matching here because we can't check the equality of values
if (stylePaint.imageHash) { | ||
const image = figma.getImageByHash(stylePaint.imageHash); | ||
const bytes = await image?.getBytesAsync(); | ||
return bytes === imageArrayBuffer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this will always return false
since 2 objects created from different sources can never be identical. This would require a byte per byte comparison I think which - in my opinion - is not worth the performance trade off
FYI @six7
You're right, I feel we can do what you said and not do any style matching. We should still be able to apply a style if name matches, and in the future we could store asset tokens in non-local styles as well. So then lets remove the parts of the code that do the matching and the style id backup parts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few things:
- When we apply a token and we fail to fetch, can we show an ErrorNotification in the Figma UI? we do this in other places already (notifyTo..)
…-add-support-for-asset-tokens
https://www.loom.com/share/831546f59ed641f592826eab3cf62d2a