Skip to content

Commit b41ff7d

Browse files
authored
Merge pull request #31 from jembezmamy/fix-hierarchy-request-error-with-empty-yield
Fix hierarchy request error with empty yield
2 parents a58f297 + 6b585d9 commit b41ff7d

File tree

2 files changed

+68
-16
lines changed

2 files changed

+68
-16
lines changed

react-migration-toolkit/src/components/react-bridge.gts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,27 @@ export default class ReactBridge<
6161
R = ComponentType,
6262
> extends Component<ReactBridgeArgs<T, R>> {
6363
tagName = (this.args.tagName ?? 'div') as T;
64+
or = (a: unknown, b: unknown) => a ?? b;
6465
<template>
6566
{{#let (element this.tagName) as |Tag|}}
66-
<Tag
67-
class={{unless @tagName 'react-bridge-wrapper'}}
68-
data-test-react-bridge-component
69-
{{! @glint-nocheck }}
70-
{{reactModifier
71-
reactComponent=@reactComponent
72-
props=(transformPropsWithLegacyContent @props)
73-
providerOptions=@providerOptions
74-
hasBlock=(has-block)
75-
}}
76-
...attributes
77-
>
78-
{{~#if (has-block)~}}
79-
{{yield}}
80-
{{/if}}
81-
</Tag>
67+
{{#let (this.or @hasBlock (has-block)) as |normalizedHasBlock|}}
68+
<Tag
69+
class={{unless @tagName 'react-bridge-wrapper'}}
70+
data-test-react-bridge-component
71+
{{! @glint-nocheck }}
72+
{{reactModifier
73+
reactComponent=@reactComponent
74+
props=(transformPropsWithLegacyContent @props)
75+
providerOptions=@providerOptions
76+
hasBlock=normalizedHasBlock
77+
}}
78+
...attributes
79+
>
80+
{{~#if normalizedHasBlock~}}
81+
{{yield}}
82+
{{/if}}
83+
</Tag>
84+
{{/let}}
8285
{{/let}}
8386
</template>
8487
}

test-app/tests/integration/components/react-bridge-test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,55 @@ module('Integration | Component | react-bridge', function (hooks) {
9090
});
9191
});
9292

93+
module('when an empty block is passed', function () {
94+
test('it should not pass children to the react component', async function (assert) {
95+
this.setProperties({
96+
reactExample: Example,
97+
props: {
98+
text: 'props content',
99+
},
100+
});
101+
102+
await render(hbs`
103+
<ReactBridge
104+
@reactComponent={{this.reactExample}}
105+
@props={{this.props}}
106+
@hasBlock={{false}}
107+
> </ReactBridge>
108+
`);
109+
110+
assert.dom('[data-test-children]').doesNotExist();
111+
});
112+
113+
test('it should rerender without an error', async function (assert) {
114+
this.setProperties({
115+
reactExample: Example,
116+
props: {
117+
text: 'props content',
118+
},
119+
});
120+
121+
await render(hbs`
122+
<ReactBridge
123+
@reactComponent={{this.reactExample}}
124+
@props={{this.props}}
125+
@hasBlock={{false}}
126+
> </ReactBridge>
127+
`);
128+
129+
assert.dom('[data-test-children]').doesNotExist();
130+
131+
this.setProperties({
132+
reactExample: Example,
133+
props: {
134+
text: 'another text',
135+
},
136+
});
137+
138+
assert.dom('[data-test-children]').doesNotExist();
139+
});
140+
});
141+
93142
test('it can access the Ember application instance', async function (assert) {
94143
await render(hbs`
95144
<ReactBridge @reactComponent={{this.reactExample}} />

0 commit comments

Comments
 (0)