Skip to content

Commit 41e125b

Browse files
fix(combinator): DLT-3232 pass app context to renderer target for directive resolution (#1301)
1 parent a5aa3e7 commit 41e125b

3 files changed

Lines changed: 86 additions & 5 deletions

File tree

packages/combinator/src/components/renderer/renderer_target.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</template>
66

77
<script setup>
8-
import { capitalize, computed, h, nextTick, onMounted, onUpdated, ref, render, useSlots } from 'vue';
8+
import { capitalize, computed, getCurrentInstance, h, nextTick, onMounted, onUpdated, ref, render, useSlots } from 'vue';
99
import { DtNotice } from '@dialpad/dialtone-vue';
1010
1111
const ERROR_MESSAGE = 'Invalid combination';
@@ -50,6 +50,11 @@ const emit = defineEmits([
5050
5151
const slots = useSlots();
5252
53+
// Standalone render() creates an app-less context; attaching appContext here
54+
// lets the target component and all its children (including DtcNode slots)
55+
// resolve globally registered components, directives, and provides.
56+
const { appContext } = getCurrentInstance();
57+
5358
/**
5459
* Map object containing events and their respective handlers.
5560
*
@@ -114,11 +119,13 @@ function renderTarget () {
114119
const slotKey = Object.keys(slots).sort().join(',');
115120
116121
try {
117-
render(h(props.component, {
122+
const vnode = h(props.component, {
118123
...filteredBindings,
119124
...events.value,
120125
key: slotKey,
121-
}, slots), currentContainer);
126+
}, slots);
127+
vnode.appContext = appContext;
128+
render(vnode, currentContainer);
122129
} catch (e) {
123130
console.warn('Rendering warning: \n', e);
124131
currentContainer = freshContainer();
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import DtcNode from './node.vue';
2+
3+
import { expect } from 'vitest';
4+
import { mount } from '@vue/test-utils';
5+
6+
describe('node.vue test', function () {
7+
describe('When a globally registered directive is used in the slot template', function () {
8+
let wrapper;
9+
let mountedSpy;
10+
11+
beforeEach(function () {
12+
mountedSpy = { called: false };
13+
14+
wrapper = mount(DtcNode, {
15+
props: {
16+
template: '<div v-x-test></div>',
17+
},
18+
global: {
19+
directives: {
20+
'x-test': {
21+
mounted () { mountedSpy.called = true; },
22+
},
23+
},
24+
},
25+
});
26+
});
27+
28+
afterEach(function () {
29+
wrapper.unmount();
30+
});
31+
32+
it('Should fire the directive mounted hook', function () {
33+
expect(mountedSpy.called).toBe(true);
34+
});
35+
});
36+
37+
describe('When a component is passed via the library prop', function () {
38+
let wrapper;
39+
40+
beforeEach(function () {
41+
const StubComponent = {
42+
name: 'StubComponent',
43+
template: '<span class="stub-rendered">stub</span>',
44+
};
45+
46+
wrapper = mount(DtcNode, {
47+
props: {
48+
template: '<stub-component />',
49+
library: { StubComponent },
50+
},
51+
});
52+
});
53+
54+
afterEach(function () {
55+
wrapper.unmount();
56+
});
57+
58+
it('Should render the library component', function () {
59+
expect(wrapper.find('.stub-rendered').exists()).toBe(true);
60+
});
61+
});
62+
});

packages/combinator/src/variants/variants_box.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,28 @@ export default {
9090
},
9191
},
9292

93-
'sized': {
93+
'fixed height with scrollbar': {
9494
props: {
9595
padding: { initialValue: '200' },
9696
surface: { initialValue: 'moderate' },
9797
borderWidth: { initialValue: '100' },
9898
inlineSize: { initialValue: '500' },
9999
blockSize: { initialValue: '600' },
100+
scrollbar: { initialValue: 'always' },
100101
},
101102
slots: {
102-
default: { initialValue: 'Fixed size' },
103+
default: { initialValue: `<dt-stack gap="200">
104+
<dt-text as="p" kind="body" size="200">Paragraph 1: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</dt-text>
105+
<dt-text as="p" kind="body" size="200">Paragraph 2: Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</dt-text>
106+
<dt-text as="p" kind="body" size="200">Paragraph 3: Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</dt-text>
107+
<dt-text as="p" kind="body" size="200">Paragraph 4: Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</dt-text>
108+
<dt-text as="p" kind="body" size="200">Paragraph 5: Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.</dt-text>
109+
<dt-text as="p" kind="body" size="200">Paragraph 6: Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit.</dt-text>
110+
<dt-text as="p" kind="body" size="200">Paragraph 7: Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit.</dt-text>
111+
<dt-text as="p" kind="body" size="200">Paragraph 8: Ut labore et dolore magnam aliquam quaerat voluptatem.</dt-text>
112+
<dt-text as="p" kind="body" size="200">Paragraph 9: Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur.</dt-text>
113+
<dt-text as="p" kind="body" size="200">Paragraph 10: At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum.</dt-text>
114+
</dt-stack>` },
103115
},
104116
},
105117

0 commit comments

Comments
 (0)