diff --git a/d2ir/compile.go b/d2ir/compile.go
index 88dd960f0..66eb97818 100644
--- a/d2ir/compile.go
+++ b/d2ir/compile.go
@@ -509,6 +509,21 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext)
func (c *compiler) updateLinks(m *Map) {
for _, f := range m.Fields {
if f.Name == "link" {
+ val := f.Primary().Value.ScalarString()
+ link, err := d2parser.ParseKey(val)
+ if err != nil {
+ continue
+ }
+
+ linkIDA := link.IDA()
+ if len(linkIDA) == 0 {
+ continue
+ }
+
+ // When updateLinks is called, all valid board links are already compiled and changed to the qualified path beginning with "root"
+ if linkIDA[0] != "root" {
+ continue
+ }
bida := BoardIDA(f)
aida := IDA(f)
if len(bida) != len(aida) {
diff --git a/e2etests-cli/main_test.go b/e2etests-cli/main_test.go
index 32f5ec26f..5f036cd61 100644
--- a/e2etests-cli/main_test.go
+++ b/e2etests-cli/main_test.go
@@ -78,6 +78,17 @@ func TestCLI_E2E(t *testing.T) {
assert.TestdataDir(t, filepath.Join(dir, "empty-layer"))
},
},
+ {
+ name: "layer-link",
+ run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
+ writeFile(t, dir, "test.d2", `doh: { link: layers.test2 }; layers: { test2: @test2.d2 }`)
+ writeFile(t, dir, "test2.d2", `x: I'm a Mac { link: https://example.com }`)
+ err := runTestMain(t, ctx, dir, env, "test.d2", "layer-link.svg")
+ assert.Success(t, err)
+
+ assert.TestdataDir(t, filepath.Join(dir, "layer-link"))
+ },
+ },
{
// Skip the empty base board so the animation doesn't show blank for 1400ms
name: "empty-base",
diff --git a/e2etests-cli/testdata/TestCLI_E2E/layer-link/index.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/layer-link/index.exp.svg
new file mode 100644
index 000000000..e069c408c
--- /dev/null
+++ b/e2etests-cli/testdata/TestCLI_E2E/layer-link/index.exp.svg
@@ -0,0 +1,110 @@
+
diff --git a/e2etests-cli/testdata/TestCLI_E2E/layer-link/test2.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/layer-link/test2.exp.svg
new file mode 100644
index 000000000..ec958858e
--- /dev/null
+++ b/e2etests-cli/testdata/TestCLI_E2E/layer-link/test2.exp.svg
@@ -0,0 +1,110 @@
+I'm a Mac
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+