Template API: executeTemplate() fails on instances found via findLayers and findConnectedInstances
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- react, typescript
- Área
- tooling
Línea de trabajo
Compare how the Template API handles instances returned by findInstance, findLayers, and findConnectedInstances, focusing on why only the single result renders through executeTemplate().example. Reproduce with the reported nested component case using the React parser and Template API; done means instances found by the multi-result methods render their expected snippets. The issue does not name source files or tests, so locate the relevant implementation and test entry points first.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
When using the Figma Template API for nested component rendering (Code Connect), there is a significant inconsistency between discovery methods. While findInstance successfully allows for snippet generation of a child component, methods that support multiple results (findLayers, findConnectedInstances) fail to render the underlying templates.
Environment
@figma/code-connect CLI: v1.4.4
Parser: React
Template Format: Template API (
.figma.tswithid,imports,example)
Test Case & Findings
Goal: Dynamically find and render all child components (Buttons, Selects, Inputs) within a parent component (Modal) using the Template API.
1. findInstance(layerName) — Working (Limited)
Result: Success, but limited to a single instance.
Behavior: Correctly finds the layer and
executeTemplate().examplereturns the full, expected code snippet.Limitation: It only returns the first match. If a Modal has two Buttons, the second one is inaccessible.
2. findLayers(selectorFn) — Broken Rendering
Result: Finds layers, but cannot render.
Behavior: It correctly identifies the number of children (e.g.,
layers.length = 6). However, callingexecuteTemplate().exampleon these handles returns empty/null.Suspected Bug: The handles returned by
findLayersseem to be "unresolved" compared to those fromfindInstance.
3. findConnectedInstances() — Fails to Locate
Result: Failed (0 results found).
Behavior: Despite documentation suggesting this for nested compositions, it returns an empty array even when
traverseInstances: trueis set and children have valid Code Connect files.
4. getInstanceSwap(propName) — Partial Failure
Result: Returns reference only.
Behavior: It finds the swap instance but fails to render the internal structure of the swapped component, returning only a placeholder name or layer name instead of the code snippet.
Comparison Table
Method: findInstance | Discovery: ✅ | executeTemplate Works?: ✅ | Multi-instance Support?: ❌ (Single only)
Method: findLayers | Discovery: ✅ | executeTemplate Works?: ❌ (Empty result) | Multi-instance Support?: ✅
Method: findConnectedInstances | Discovery: ❌ | executeTemplate Works?: — | Multi-instance Support?: ✅
Method: getInstanceSwap | Discovery: ✅ | executeTemplate Works?:⚠️ (Name only) | Multi-instance Support?:❌
Impact
This issue makes dynamic nested composition impossible. Currently, we cannot dynamically loop through and render a variable number of children (e.g., form elements in a Modal body or multiple buttons in a footer) because the methods that find multiple children do not support rendering.
The only "workaround" is manually calling findInstance for every known layer name, which is not scalable and fails when multiple instances share the same name.
Steps to Reproduce
Create a parent component using the Template API format.
Create multiple child components also using the Template API format (including
idandmetadata: { nestable: true }).Attempt to use
findLayersto map through children and callexecuteTemplate().exampleon each.Observe that the returned value is empty.
Expected Behavior
Any component handle returned by findLayers or findConnectedInstances should behave identically to the handle returned by findInstance, allowing executeTemplate() to produce the correct code snippet.
Proposed Fix/Action
Investigate why handles from
findLayerslose their template context.Ensure
findConnectedInstancescorrectly identifies children using the Template API format.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.6k
- Forks
- 126
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de figma/code-connect
-
normalizePropName strips `#` characters from Figma property names instead of only the `#id` suffixAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
figma/code-connect#419 ·
-
feature request
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
figma/code-connect#403 ·
-
feature request
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
figma/code-connect#414 ·
-
feature request
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
figma/code-connect#413 · 1 comentario ·
-
feature request
Dificultad 4/5 3-5 días Aptitud para principiantes 54/100
figma/code-connect#412 · 1 comentario ·
Todos los issues de figma/code-connect
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
vercel-labs/ui#540 ·
Los mantenedores suelen responder en 1 día
-
accepted ai-dev ai-implementing
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
livesport/homer#218 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Negative values skip k/M abbreviation and medium decimal format on line, stacked-area, and tooltipAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
britecharts/britecharts#1255 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
jeanibarz/knowledge-base-mcp-server#1268 ·
Los mantenedores suelen responder en 1 día