figma / code-snippet-editor-plugin

Translate component variants, properties, and more into dynamic code snippets for your design system.
https://www.figma.com/community/plugin/1311777988952403297/code-snippet-editor
MIT License
126 stars 11 forks source link

Error `{}` #10

Closed gossi closed 5 months ago

gossi commented 5 months ago

I'm running into an issue and this might be because I'm using this plugin wrong and then this is a question to use it correctly - or - if I'm using the plugin correctly, then I likely found a bug.

What I see:

Bildschirmfoto 2024-01-30 um 15 07 11

Repro Steps:

A) In my components file:

B) I another file:

Expectation:

I would see the code in my other file as I'd seen this for the instances I tested them with in the same file.

jake-figma commented 5 months ago

let me see if i can't repro. thanks for reporting.

jake-figma commented 5 months ago

I am unable to reproduce and can successfully see code snippets for published library components. Is it possible you didn't update the library in the second file?

The fact that this says "error" in the title is a little confusing to me, unsure how that can happen at a code level. Does a red message pop up in Figma / are there errors in the JS console? CleanShot 2024-02-05 at 13 02 50

EDIT: I suppose another scenario would be if you added the template to the instance instead of the main component. You can add a template to any node, including an instance. If you want to have it stored in the library itself, you want to make sure youre adding the template to the main component / component set, not the instance.

jake-figma commented 5 months ago

Able to repro the "error" state, but by doing something else entirely. Looking into this now!

jake-figma commented 5 months ago

I believe this occurs when what was saved to plugin data wasnt a valid CodegenResult[] template array. I am going to write a guard on that.

jake-figma commented 5 months ago

can confirm that this is actually my generic guard whenever an error happens. going to add a line that logs errors in the console/code so that we can debug.

jake-figma commented 5 months ago

can you try and repro and see what shows up in the code panel now? commit: https://github.com/figma/code-snippet-editor-plugin/commit/37fa6adbc557e1ef9d9bb6bc3cf65d236518a069 should yield more information in the code snippet area now.

gossi commented 5 months ago

It shows the code again in the inspect panel. Thanks a lot.

Here is a screenshot of the console from Figma. But its also a series of logs I see (like double entries).

Bildschirmfoto 2024-02-06 um 10 52 20

I opened both:

Bildschirmfoto 2024-02-06 um 10 50 50

Here is the code snippet definition for that component:

Bildschirmfoto 2024-02-06 um 10 54 25

PS. What I was seeing (didn't take a screenshot here). When inspecting the component, then it showed in a green alert, that something with regards to the code snippet was updated and I either x'ed it away or said ok.

jake-figma commented 5 months ago

Ok so I am hearing that it sounds like this is resolved? If so I'll close this issue.

Two things:

gossi commented 5 months ago

Awesome, great job! Thanks a lot