Skip to content

Commit 6e6758f

Browse files
authored
Merge pull request #4538 from easyops-cn/steve/v3-fix-rerender
Steve/v3-fix-rerender
2 parents 4d4bc39 + 4e8953f commit 6e6758f

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

packages/monaco-contributions/yaml.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ export const conf = {
1919
{ open: '"', close: '"' },
2020
{ open: "'", close: "'" },
2121
],
22-
surroundingPairs: [
23-
{ open: "{", close: "}" },
24-
{ open: "[", close: "]" },
25-
{ open: "(", close: ")" },
26-
{ open: '"', close: '"' },
27-
{ open: "'", close: "'" },
28-
],
2922
folding: {
3023
offSide: true,
3124
},
@@ -312,9 +305,10 @@ export const language = {
312305
[
313306
/(<%[~=]?)/,
314307
{
315-
token: "white",
308+
token: "delimiter",
316309
next: "@expressionEmbedded",
317310
nextEmbedded: "text/javascript",
311+
bracket: "@open",
318312
},
319313
],
320314
[

packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function setupTemplateProxy(
5858

5959
if (slotProxies && slotted) {
6060
throw new Error(
61-
`Can not have proxied slot ref when the parent has a slot element child, check your template "${hostBrick.type}" and ref "${ref}"`
61+
`Can not have proxied slot ref when the ref target has a slot element child, check your template "${hostBrick.type}" and ref "${ref}"`
6262
);
6363
}
6464

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3447,7 +3447,7 @@ describe("renderBrick for tpl", () => {
34473447
{}
34483448
)
34493449
).rejects.toMatchInlineSnapshot(
3450-
`[Error: Can not have proxied slot ref when the parent has a slot element child, check your template "my.tpl-m" and ref "main"]`
3450+
`[Error: Can not have proxied slot ref when the ref target has a slot element child, check your template "my.tpl-m" and ref "main"]`
34513451
);
34523452
});
34533453
});

packages/runtime/src/internal/Renderer.ts

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,26 @@ async function legacyRenderBrick(
503503
}
504504
};
505505

506-
const renderControlNode = async (
507-
runtimeContext: RuntimeContext,
508-
type: "initial" | "rerender"
509-
) => {
506+
type RenderControlNodeOptions =
507+
| {
508+
type: "initial";
509+
runtimeContext: RuntimeContext;
510+
tplStateStoreScope?: undefined;
511+
formStateStoreScope?: undefined;
512+
}
513+
| {
514+
type: "rerender";
515+
runtimeContext: RuntimeContext;
516+
tplStateStoreScope: DataStore<"STATE">[];
517+
formStateStoreScope: DataStore<"FORM_STATE">[];
518+
};
519+
520+
const renderControlNode = async ({
521+
type,
522+
runtimeContext,
523+
tplStateStoreScope,
524+
formStateStoreScope,
525+
}: RenderControlNodeOptions) => {
510526
let changedAfterInitial = false;
511527
const tracker: InitialTracker = {
512528
disposes: [],
@@ -531,6 +547,16 @@ async function legacyRenderBrick(
531547
tracker,
532548
uninitialized && type === "initial"
533549
);
550+
551+
// Changes may happen during `postAsyncRender`.
552+
if (!changedAfterInitial && type === "rerender") {
553+
const scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
554+
await postAsyncRender(rawOutput, runtimeContext, [
555+
runtimeContext.ctxStore,
556+
...scopedStores,
557+
]);
558+
}
559+
534560
tracker.disposes.forEach((dispose) => dispose());
535561
tracker.disposes.length = 0;
536562
uninitialized = false;
@@ -549,7 +575,10 @@ async function legacyRenderBrick(
549575
return rawOutput!;
550576
};
551577

552-
const controlledOutput = await renderControlNode(runtimeContext, "initial");
578+
const controlledOutput = await renderControlNode({
579+
type: "initial",
580+
runtimeContext,
581+
});
553582

554583
const { onMount, onUnmount } = brickConf.lifeCycle ?? {};
555584

@@ -561,17 +590,12 @@ async function legacyRenderBrick(
561590
const [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] =
562591
createScopedRuntimeContext(runtimeContext);
563592

564-
const reControlledOutput = await renderControlNode(
565-
scopedRuntimeContext,
566-
"rerender"
567-
);
568-
569-
const scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
570-
await postAsyncRender(
571-
reControlledOutput,
572-
scopedRuntimeContext,
573-
scopedStores
574-
);
593+
const reControlledOutput = await renderControlNode({
594+
type: "rerender",
595+
runtimeContext: scopedRuntimeContext,
596+
tplStateStoreScope,
597+
formStateStoreScope,
598+
});
575599

576600
// Ignore stale renders
577601
if (renderId === currentRenderId) {
@@ -596,7 +620,7 @@ async function legacyRenderBrick(
596620
)(new CustomEvent("mount", { detail: { rerender: true } }));
597621
}
598622

599-
for (const store of scopedStores) {
623+
for (const store of [...tplStateStoreScope, ...formStateStoreScope]) {
600624
store.mountAsyncData();
601625
}
602626
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ describe("useBrick", () => {
267267
});
268268

269269
test("tpl", async () => {
270+
mockInternalApiGetRuntimeContext.mockReturnValue({
271+
ctxStore: new DataStore("CTX"),
272+
} as RuntimeContext);
270273
consoleInfo.mockReturnValue();
271274
customTemplates.define("my.tpl-a", {
272275
state: [
@@ -472,6 +475,7 @@ describe("useBrick", () => {
472475
unmountUseBrick(renderResult, mountResult);
473476

474477
consoleInfo.mockReset();
478+
mockInternalApiGetRuntimeContext.mockReturnValue(undefined);
475479
});
476480

477481
test("root as portal", async () => {

0 commit comments

Comments
 (0)