1. How swift-docc-render consumes this
The pattern is identical everywhere it's used: a content node never embeds its target's URL, title,
or metadata directly — it embeds only an identifier string, and the consumer resolves
that string against the render node's top-level references object at render time. The
clearest example is the reference inline kind's dispatch arm in
ContentNode.vue's renderNode() factory:
case InlineType.reference: {
const reference = references[node.identifier];
if (!reference) return null;
...
}
(ContentNode.vue#L467-L487.)
The image inline kind does the same lookup one branch earlier in the same function
(const image = references[node.identifier]; if (!image) return null;,
ContentNode.vue#L442-L458).
The dictionary itself flows down from the top-level RenderNode as a prop, then gets re-exposed to
every deeply nested content component through a shared mixin,
src/mixins/referencesProvider.js,
rather than threaded through props at every level — which is why a reference node
buried five components deep inside a tutorial step can still resolve against the same one map the
top-level article body uses.
The failure mode is consistent across every consumer of this map: if node.identifier
has no matching key, the lookup returns undefined, the guard clause fires, and the whole
node renders as nothing (return null). There is no broken-link placeholder, no console
warning, no fallback text — a dangling reference is silently invisible in the rendered page. This
is a deliberate simplicity/robustness tradeoff, not a bug: DocC guarantees at build time that every
identifier it emits has a matching references entry (unresolved links are
caught and reported as build warnings before the archive is ever written), so swift-docc-render's
job is just to render what's there, not to validate archive integrity.
2. Worked example: two different kinds, one map
Real fixtures, spliced from two different sources to show the pattern generalizing across kinds (the
first pairing is drawn directly from
Tests/SwiftDocCTests/Rendering/Rendering Fixtures/term-lists-1.json and
external-location-custom-url.json; the second reuses the
plus.svg icon fixture from Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift,
lines 803-818, also cited on
reference-image.html):
{
"type": "paragraph",
"inlineContent": [
{ "type": "text", "text": "See " },
{ "type": "reference", "identifier": "doc://org.swift.docc.example/downloads/sample.zip",
"isActive": true, "overridingTitle": "Download" },
{ "type": "text", "text": " for the full project, or click " },
{ "type": "image", "identifier": "plus.svg" },
{ "type": "text", "text": " to add one." }
]
}
Both identifiers resolve against the same top-level map, even though one arm is a
FileRenderReference and the other an ImageRenderReference:
"references": {
"doc://org.swift.docc.example/downloads/sample.zip": {
"type": "file",
"identifier": "doc://org.swift.docc.example/downloads/sample.zip",
"url": "/downloads/sample.zip",
"title": "sample.zip"
},
"plus.svg": {
"type": "image",
"identifier": "plus.svg",
"alt": "A plus icon.",
"variants": [
{ "url": "/images/org.swift.docc.Book/plus.svg", "traits": ["1x", "light"], "svgID": "plus-id" }
]
}
}
Both nodes go through the same two-step dance — look up node.identifier in
references, then dispatch on the resolved object's own type discriminator
("file" vs. "image") to decide which Vue component and props to build. The
reference node ends up as an <a class="inline-link">Download</a>; the
image node ends up as a <picture>/<img> pair (see
Assets for how the variants array inside an
image reference becomes that markup). Nothing about the lookup step itself differs between
the two — only what happens after the resolved object's own type field is read.
3. Data sheet
Source: Sources/DocCArchive/Vendored/RenderNode.spec.json. RenderNode.references
is a free-form object (map of string identifier → RenderReference) rather than a typed
array, generated as Components.Schemas.RenderReferenceMap, a dictionary keyed by
String with Components.Schemas.RenderReference values. RenderReference
itself (schema around line 1491) is a oneOf discriminated union with exactly nine members,
each identifiable by its own type discriminator string:
| Reference kind | Wire type | Documented on |
|---|---|---|
ImageRenderReference | "image" | reference-image.html |
VideoRenderReference | "video" | reference-video.html |
FileRenderReference | "file" | reference-file.html |
FileTypeRenderReference | "fileType" | reference-filetype.html |
XcodeRequirementRenderReference | "xcodeRequirement" | reference-xcoderequirement.html |
TopicRenderReference | "topic" | reference-topic.html, node-section.html |
DownloadRenderReference | "download" | reference-download.html |
UnresolvableRenderReference | "unresolvable" | reference-unresolvable.html |
LinkRenderReference | "link" | reference-link.html |
Every member shares two required fields regardless of kind — type (the discriminator)
and identifier (the dictionary key this object is stored under, duplicated onto the object
itself for self-description, matching swift-docc's RenderReference protocol requirement at
Sources/SwiftDocC/Model/Rendering/References/RenderReference.swift:29). Everything past
those two fields is kind-specific: an ImageRenderReference carries variants
and alt; a TopicRenderReference carries title,
abstract, kind, role, and a resolved url; an
UnresolvableRenderReference carries just a title string, since by
definition there's no URL or richer content to show for a link DocC couldn't resolve at build time.
"Section," despite appearing as a distinct concept in the page-hierarchy docs, is not a tenth
reference kind — it's a type: "section" value nested inside a
TopicRenderReference, not a top-level arm of this union.
4. Where else this shows up
A non-exhaustive but representative list of nodes that resolve against references:
image and
reference inline nodes;
links and
video block content;
section nodes (topic groups resolve their child
identifiers this way); and reference-dictionary entries that themselves nest further identifiers,
such as a download reference's associated file. The
same identifier-then-lookup shape also appears one level up, in the archive's
index/index.json (icon references on index nodes) and in
linkable-entities.json (each entry carries its own nested references map)
— see Archive Structure §3 and §6.
5. Modern CSS-only alternative
Not applicable
The lookup itself is a one-shot, build-time-equivalent dictionary read with no reactive state, no user interaction, and no toggled visibility — there is nothing here for a CSS-only mechanism to replace. (Individual reference kinds have their own Modern CSS verdicts where a real interactive mechanism exists downstream of the lookup — e.g. the light/dark asset selection covered on Assets — but the map-resolution step itself is inert.)