Giter VIP home page Giter VIP logo

Comments (6)

jamillazarev avatar jamillazarev commented on July 21, 2024

I think it could be for two reasons.

  1. Plugin works laggy with text nodes. This is most likely due to the fact that you have one extra loop inside loadFonts(selection). This can be fixed by changing to loadFonts(node), and removing loop through selection from the function.
  2. figma.loadFontAsync() inside a loop. It would be better to use Promise.all()

However, note that loadFontAsync returns a Promise. Even a Promise resolves immediately, it still needs to round-trip to the JavaScript event loop. So you probably shouldn't call loadFontAsync on the same font repeatedly inside a loop.
https://www.figma.com/plugin-docs/api/properties/figma-loadfontasync/#docsNav

from fromcss.

taitems avatar taitems commented on July 21, 2024

Good point. I believe at least one loop is necessary as it has to loop through all sub node ranges to be able to load in all the different variants as pictured below:

image

from fromcss.

taitems avatar taitems commented on July 21, 2024

Hmm yeah as I feared:

  • The first outer loop is necessary to apply to more than one text element being selected
  • The second inner loop is needed to get the individual text ranges inside

image

Two suggestions:

  • Is there a way to memoize? Maybe _.memoize or some Vue alternative?
  • Do we need to go character by character or can we load 0, len instead of i, i+1?

from fromcss.

jamillazarev avatar jamillazarev commented on July 21, 2024

I may have misspelled my point. I haven't practiced my English for a long time ๐Ÿ™ƒ

About extra loop: I uploaded this fix here https://github.com/jamillazarev/fromCSS/tree/fix-perfomance-of-updating-text-nodes
About caching: Vue has computed properties https://vuejs.org/v2/guide/computed.html

Based on the documentation, figma caches this aspect itself. It seems to me that we should try to wait for all the promises.

from fromcss.

jamillazarev avatar jamillazarev commented on July 21, 2024

As far as I can see after a little refactoring, everything works fine. However, I noticed other issues...

from fromcss.

jamillazarev avatar jamillazarev commented on July 21, 2024

After restarting figma, the problem returned... ๐Ÿคจ
Screen Shot 2021-01-15 at 20 38 15

from fromcss.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.