You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance README with detailed explanations of `data-hygraph-component-… (#2)
* Enhance README with detailed explanations of `data-hygraph-component-chain` and related attributes, including examples for single-level and deeply nested components.
* bump version
* fix description
@@ -108,54 +108,312 @@ Common optional attributes:
108
108
109
109
### Tagging Component Fields
110
110
111
-
Use the optional `data-hygraph-component-chain` attribute when a field lives inside a modular component, repeatable component list, or union component. The attribute accepts a JSON string array describing the path from the entry to the nested field.
111
+
Use the `data-hygraph-component-chain` attribute when a field lives inside a modular component, repeatable component list, or union component. The component chain tells Studio how to navigate from the root entry to the specific nested field.
112
+
113
+
#### Key Concepts
114
+
115
+
| Attribute | Value | Purpose |
116
+
|-----------|-------|---------|
117
+
|`data-hygraph-entry-id`| Always the **root page/entry ID**| Identifies which Hygraph entry contains this content |
118
+
|`data-hygraph-field-api-id`| The component field name in your schema | Identifies which field to open in the editor |
119
+
|`data-hygraph-component-chain`| JSON array of `{fieldApiId, instanceId}`| Describes the path from root entry to the nested field |
120
+
121
+
**Important:**`data-hygraph-entry-id` is always the root entry ID (e.g., page or article), even for deeply nested components. The component chain handles the navigation to nested fields—you never use the component's ID as the entry ID.
122
+
123
+
#### What is `instanceId`?
124
+
125
+
The `instanceId` is the unique identifier for each component instance, returned by Hygraph in your GraphQL response:
126
+
127
+
```graphql
128
+
query {
129
+
page(where: { id: "page_123" }) {
130
+
id # Root entry ID → use for data-hygraph-entry-id
131
+
title
132
+
contentSections { # Modular component field
133
+
...onHeroSection {
134
+
id # ← This is the instanceId for the component chain
135
+
headline
136
+
subheadline
137
+
}
138
+
...onFeatureGrid {
139
+
id # ← instanceId
140
+
features {
141
+
id # ← instanceId for nested components
142
+
title
143
+
description
144
+
}
145
+
}
146
+
}
147
+
}
148
+
}
149
+
```
112
150
113
-
Each element in the array must contain:
114
-
-`fieldApiId`: the API ID of the component field in your schema
115
-
-`instanceId`: the ID returned by Hygraph for that component entry
151
+
#### Single-Level Components
152
+
153
+
For a field inside a component list (e.g., `Page.contentSections[]`):
{/* Render nested features with extended chain */}
264
+
</section>
265
+
);
266
+
267
+
default:
268
+
returnnull;
269
+
}
270
+
})}
138
271
```
139
272
140
-
Union components work the same way—the chain lists each component hop down to the field you want to tag. Always serialize the array with double quotes so the HTML attribute remains valid.
273
+
#### Complete Example: Page with Modular Content
141
274
142
-
> Tip: Instead of hand-writing JSON strings, use the helpers exported from `@hygraph/preview-sdk/core`:
143
-
> ```tsx
144
-
>import {
145
-
> createPreviewAttributes,
146
-
> createComponentChainLink,
147
-
> } from'@hygraph/preview-sdk/core';
275
+
Here's a full example showing a page template with multiple component types and nesting:
0 commit comments