Skip to content

Commit ee26b6f

Browse files
authored
Merge pull request #4797 from easyops-cn/steve/v3-isolated-templates
Steve/v3-isolated-templates
2 parents 0c0367f + 1cd3f42 commit ee26b6f

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

packages/runtime/src/CustomTemplates.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,18 @@ describe("customTemplates", () => {
102102
runtimeContext,
103103
};
104104
(refA.element as any).propA = "a2";
105-
const methodM = ((refA.element as any).methodM = jest.fn(() => "M"));
105+
const methodM = ((refA.element as any).methodM = jest.fn(
106+
(_v?: unknown) => "M"
107+
));
106108
const refB: RuntimeBrick = {
107109
type: "div",
108110
element: document.createElement("div"),
109111
runtimeContext,
110112
};
111113
(refB.element as any).propC = "b2";
112-
const methodL = ((refB.element as any).methodL = jest.fn(() => "L"));
114+
const methodL = ((refB.element as any).methodL = jest.fn(
115+
(_v?: unknown) => "L"
116+
));
113117
const hostBrick: RuntimeBrick = {
114118
type: "tpl-proxy",
115119
tplHostMetadata: {
@@ -322,5 +326,9 @@ describe("customTemplates", () => {
322326
const tpl = document.createElement("tpl-existed") as RuntimeBrickElement;
323327
expect(tpl.$$typeof).toBe(undefined);
324328
expect(tpl.constructor).toBe(TplExistedElement);
329+
330+
// No effect for non-isolated registry
331+
customTemplates.clearIsolatedRegistry();
332+
expect(customTemplates.get("tpl-existed")).toBeDefined();
325333
});
326334
});

packages/runtime/src/createRoot.spec.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { unstable_createRoot } from "./createRoot.js";
33
import { applyTheme } from "./themeAndMode.js";
44

55
initializeI18n();
6-
const consoleError = jest.spyOn(console, "error");
76
jest.mock("./themeAndMode.js");
87
window.scrollTo = jest.fn();
98

@@ -200,6 +199,7 @@ describe("preview", () => {
200199
});
201200

202201
test("unknown bricks", async () => {
202+
const consoleError = jest.spyOn(console, "error");
203203
consoleError.mockReturnValue();
204204
const root = unstable_createRoot(container, { unknownBricks: "silent" });
205205

@@ -230,6 +230,7 @@ describe("preview", () => {
230230
root.unmount();
231231
expect(container.innerHTML).toBe("");
232232
expect(portal.innerHTML).toBe("");
233+
consoleError.mockRestore();
233234
});
234235

235236
test("fail", async () => {
@@ -351,6 +352,8 @@ describe("preview", () => {
351352
});
352353

353354
test("templates in scope fragment", async () => {
355+
const consoleWarn = jest.spyOn(console, "warn");
356+
consoleWarn.mockReturnValue();
354357
const root = unstable_createRoot(container);
355358

356359
await root.render(
@@ -380,10 +383,43 @@ describe("preview", () => {
380383
expect(tpl?.tagName.toLowerCase()).toBe("isolated-tpl-a");
381384
expect(tpl?.innerHTML).toBe("<p>Template A</p>");
382385

386+
expect(consoleWarn).toHaveBeenCalledTimes(0);
387+
388+
// Redefine the same template.
389+
await root.render(
390+
[
391+
{
392+
brick: "isolated-tpl-a",
393+
},
394+
],
395+
{
396+
templates: [
397+
{
398+
name: "isolated-tpl-a",
399+
bricks: [
400+
{
401+
brick: "p",
402+
properties: {
403+
textContent: "Template A Updated",
404+
},
405+
},
406+
],
407+
},
408+
],
409+
}
410+
);
411+
expect(container.firstElementChild?.innerHTML).toBe(
412+
"<p>Template A Updated</p>"
413+
);
414+
expect(consoleWarn).toHaveBeenCalledTimes(1);
415+
383416
root.unmount();
417+
consoleWarn.mockRestore();
384418
});
385419

386420
test("using unknown templates in scope fragment", async () => {
421+
const consoleError = jest.spyOn(console, "error");
422+
consoleError.mockReturnValue();
387423
const root = unstable_createRoot(container);
388424

389425
await root.render([
@@ -397,5 +433,6 @@ describe("preview", () => {
397433
expect(tpl?.innerHTML).toBe("");
398434

399435
root.unmount();
436+
consoleError.mockRestore();
400437
});
401438
});

packages/theme/src/elevo.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
--elevo-component-backdrop-filter: blur(33px);
1212

1313
--elevo-input-background: rgba(255, 255, 255, 0.8);
14-
--elevo-input-box-shadow: inset 0px -1px 3px 0px
15-
rgba(var(--elevo-color-brand-rgb-channel), 0.5);
14+
--elevo-input-box-shadow: none;
1615
--elevo-placeholder-color: rgba(0, 10, 26, 0.26);
1716
}

0 commit comments

Comments
 (0)