Skip to content

Commit c2d3e93

Browse files
committed
refactor(): use abstract render nodes for routes and control nodes
1 parent 1fc8263 commit c2d3e93

File tree

12 files changed

+407
-372
lines changed

12 files changed

+407
-372
lines changed

mock-micro-apps/e2e/storyboard.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,3 +1097,33 @@ routes:
10971097
iid: 9
10981098
properties:
10991099
textContent: This should always be shown
1100+
1101+
- path: '${APP.homepage}/debug'
1102+
context:
1103+
- name: debug
1104+
value: false
1105+
bricks:
1106+
- brick: button
1107+
properties:
1108+
textContent: Toggle Debug
1109+
events:
1110+
click:
1111+
- action: context.replace
1112+
args:
1113+
- debug
1114+
- <% !CTX.debug %>
1115+
- brick: e2e.list-by-use-brick
1116+
properties:
1117+
data: [1, 2]
1118+
useBrick:
1119+
- brick: div
1120+
children:
1121+
- brick: div
1122+
portal: true
1123+
children:
1124+
- brick: :if
1125+
dataSource: <%= CTX.debug %>
1126+
children:
1127+
- brick: p
1128+
properties:
1129+
textContent: '<% `Debug: ${DATA}` %>'

packages/brick-container/scripts/start.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const server = new WebpackDevServer(
2828
hot: true,
2929
client: {
3030
overlay: false,
31+
logging: "warn",
3132
},
3233
devMiddleware: {
3334
publicPath: baseHref,

packages/react-runtime/src/ReactUseBrick.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ let ReactUseBrick = function ReactUseBrick({
7676
(element: HTMLElement | null) => {
7777
if (element) {
7878
mountResult.current = __secret_internals.mountUseBrick(
79-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8079
renderResult!,
8180
element
8281
);
8382
} else {
84-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8583
__secret_internals.unmountUseBrick(renderResult!, mountResult.current!);
8684
mountResult.current = undefined;
8785
}
@@ -102,7 +100,7 @@ let ReactUseBrick = function ReactUseBrick({
102100
return null;
103101
}
104102

105-
const WebComponent = tagName as any;
103+
const WebComponent = tagName as "div";
106104
return <WebComponent key={renderKey} ref={_refCallback} />;
107105
};
108106

packages/runtime/src/internal/Renderer.spec.ts

Lines changed: 149 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,30 +1068,31 @@ describe("renderBrick for control nodes", () => {
10681068
expect(output1).toEqual({
10691069
blockingList: [],
10701070
node: expect.objectContaining({
1071-
tag: RenderTag.BRICK,
10721071
return: renderRoot,
1073-
type: "div",
1074-
properties: {
1075-
textContent: "a",
1076-
title: "0/2",
1077-
},
1078-
slotId: undefined,
1079-
sibling: expect.objectContaining({
1072+
tag: RenderTag.ABSTRACT,
1073+
child: expect.objectContaining({
10801074
tag: RenderTag.BRICK,
1081-
return: renderRoot,
10821075
type: "div",
10831076
properties: {
1084-
textContent: "b",
1085-
title: "1/2",
1077+
textContent: "a",
1078+
title: "0/2",
10861079
},
10871080
slotId: undefined,
1081+
sibling: expect.objectContaining({
1082+
tag: RenderTag.BRICK,
1083+
type: "div",
1084+
properties: {
1085+
textContent: "b",
1086+
title: "1/2",
1087+
},
1088+
slotId: undefined,
1089+
}),
10881090
}),
10891091
}),
10901092
});
10911093
expect(output2).toEqual({
10921094
node: {
1093-
tag: RenderTag.PLACEHOLDER,
1094-
tracking: false,
1095+
tag: RenderTag.ABSTRACT,
10951096
return: {
10961097
tag: RenderTag.ROOT,
10971098
},
@@ -1623,31 +1624,36 @@ describe("renderBrick for control nodes", () => {
16231624
expect(output1).toEqual({
16241625
blockingList: [],
16251626
node: expect.objectContaining({
1626-
tag: RenderTag.BRICK,
1627+
tag: RenderTag.ABSTRACT,
16271628
return: renderRoot,
1628-
type: "div",
1629-
properties: {
1630-
textContent: "Good",
1631-
},
1632-
slotId: undefined,
1629+
child: expect.objectContaining({
1630+
tag: RenderTag.BRICK,
1631+
type: "div",
1632+
properties: {
1633+
textContent: "Good",
1634+
},
1635+
slotId: undefined,
1636+
}),
16331637
}),
16341638
});
16351639
expect(output2).toEqual({
16361640
blockingList: [],
16371641
node: expect.objectContaining({
1638-
tag: RenderTag.BRICK,
1642+
tag: RenderTag.ABSTRACT,
16391643
return: renderRoot,
1640-
type: "div",
1641-
properties: {
1642-
textContent: "Bad",
1643-
},
1644-
slotId: undefined,
1644+
child: expect.objectContaining({
1645+
tag: RenderTag.BRICK,
1646+
type: "div",
1647+
properties: {
1648+
textContent: "Bad",
1649+
},
1650+
slotId: undefined,
1651+
}),
16451652
}),
16461653
});
16471654
expect(output3).toEqual({
16481655
node: {
1649-
tag: RenderTag.PLACEHOLDER,
1650-
tracking: false,
1656+
tag: RenderTag.ABSTRACT,
16511657
return: {
16521658
tag: RenderTag.ROOT,
16531659
},
@@ -1691,28 +1697,34 @@ describe("renderBrick for control nodes", () => {
16911697
},
16921698
},
16931699
{
1694-
iid: "if-a",
16951700
brick: ":if",
1696-
dataSource: "<%= CTX.quality === 'bad' %>",
1701+
dataSource: true,
16971702
children: [
16981703
{
1699-
brick: "h2",
1700-
properties: {
1701-
textContent: "Warning",
1702-
},
1704+
iid: "if-a",
1705+
brick: ":if",
1706+
dataSource: "<%= CTX.quality === 'bad' %>",
1707+
children: [
1708+
{
1709+
brick: "h2",
1710+
properties: {
1711+
textContent: "Warning",
1712+
},
1713+
},
1714+
],
17031715
},
1704-
],
1705-
},
1706-
{
1707-
iid: "if:b",
1708-
brick: ":if",
1709-
dataSource: "<%= CTX.quality === 'bad' %>",
1710-
children: [
17111716
{
1712-
brick: "p",
1713-
properties: {
1714-
textContent: "Not good",
1715-
},
1717+
iid: "if:b",
1718+
brick: ":if",
1719+
dataSource: "<%= CTX.quality === 'bad' %>",
1720+
children: [
1721+
{
1722+
brick: "p",
1723+
properties: {
1724+
textContent: "Not good",
1725+
},
1726+
},
1727+
],
17161728
},
17171729
],
17181730
},
@@ -1751,6 +1763,90 @@ describe("renderBrick for control nodes", () => {
17511763
rendererContext.dispose();
17521764
});
17531765

1766+
test("nested if", async () => {
1767+
const container = document.createElement("div");
1768+
const portal = document.createElement("div");
1769+
const renderRoot = {
1770+
tag: RenderTag.ROOT,
1771+
container,
1772+
createPortal: portal,
1773+
} as RenderRoot;
1774+
const ctxStore = new DataStore("CTX");
1775+
const runtimeContext = {
1776+
ctxStore,
1777+
tplStateStoreMap: new Map(),
1778+
formStateStoreMap: new Map(),
1779+
pendingPermissionsPreCheck: [] as undefined[],
1780+
} as RuntimeContext;
1781+
ctxStore.define(
1782+
[
1783+
{
1784+
name: "quality",
1785+
value: "good",
1786+
},
1787+
],
1788+
runtimeContext
1789+
);
1790+
const rendererContext = new RendererContext("page");
1791+
const output = await renderBricks(
1792+
renderRoot,
1793+
[
1794+
{
1795+
brick: ":if",
1796+
dataSource: "<%= CTX.quality !== 'bad' %>",
1797+
children: [
1798+
{
1799+
iid: "if-a",
1800+
brick: ":if",
1801+
dataSource: "<%= CTX.quality === 'better' %>",
1802+
children: [
1803+
{
1804+
brick: "h2",
1805+
properties: {
1806+
textContent: "Better",
1807+
},
1808+
},
1809+
],
1810+
},
1811+
{
1812+
brick: ":if",
1813+
dataSource: true,
1814+
children: [
1815+
{
1816+
brick: "p",
1817+
properties: {
1818+
textContent: "Cool",
1819+
},
1820+
},
1821+
],
1822+
},
1823+
],
1824+
},
1825+
],
1826+
runtimeContext,
1827+
rendererContext,
1828+
[],
1829+
{}
1830+
);
1831+
renderRoot.child = output.node;
1832+
await Promise.all([...output.blockingList, ctxStore.waitForAll()]);
1833+
mountTree(renderRoot);
1834+
rendererContext.dispatchOnMount();
1835+
rendererContext.initializeScrollIntoView();
1836+
1837+
expect(container.innerHTML).toBe("<p>Cool</p>");
1838+
1839+
ctxStore.updateValue("quality", "better", "replace");
1840+
await new Promise((resolve) => setTimeout(resolve, 0));
1841+
1842+
expect(container.innerHTML).toBe("<h2>Better</h2><p>Cool</p>");
1843+
1844+
unmountTree(container);
1845+
unmountTree(portal);
1846+
rendererContext.dispatchOnUnmount();
1847+
rendererContext.dispose();
1848+
});
1849+
17541850
test("re-render dynamic nodes with portal bricks from useBrick", async () => {
17551851
const container = document.createElement("div");
17561852
const portal = document.createElement("div");
@@ -1933,13 +2029,16 @@ describe("renderBrick for control nodes", () => {
19332029
expect(output).toEqual({
19342030
blockingList: [],
19352031
node: expect.objectContaining({
1936-
tag: RenderTag.BRICK,
2032+
tag: RenderTag.ABSTRACT,
19372033
return: renderRoot,
1938-
type: "div",
1939-
properties: {
1940-
textContent: "B",
1941-
},
1942-
slotId: undefined,
2034+
child: expect.objectContaining({
2035+
tag: RenderTag.BRICK,
2036+
type: "div",
2037+
properties: {
2038+
textContent: "B",
2039+
},
2040+
slotId: undefined,
2041+
}),
19432042
}),
19442043
});
19452044
});

0 commit comments

Comments
 (0)