From 21b1f97da5ace86ce774f005bd61c33003f77920 Mon Sep 17 00:00:00 2001 From: weareoutman Date: Wed, 30 Oct 2024 11:49:32 +0800 Subject: [PATCH 1/3] fix(): refine yaml language --- packages/monaco-contributions/yaml.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/monaco-contributions/yaml.js b/packages/monaco-contributions/yaml.js index 3fb1832647..3e2bb7c9db 100644 --- a/packages/monaco-contributions/yaml.js +++ b/packages/monaco-contributions/yaml.js @@ -19,13 +19,6 @@ export const conf = { { open: '"', close: '"' }, { open: "'", close: "'" }, ], - surroundingPairs: [ - { open: "{", close: "}" }, - { open: "[", close: "]" }, - { open: "(", close: ")" }, - { open: '"', close: '"' }, - { open: "'", close: "'" }, - ], folding: { offSide: true, }, @@ -312,9 +305,10 @@ export const language = { [ /(<%[~=]?)/, { - token: "white", + token: "delimiter", next: "@expressionEmbedded", nextEmbedded: "text/javascript", + bracket: "@open", }, ], [ From ef9af92380d987c3cb23bb042dcb8e25bb57dfbe Mon Sep 17 00:00:00 2001 From: weareoutman Date: Wed, 30 Oct 2024 11:50:04 +0800 Subject: [PATCH 2/3] fix(): refine tpl slot error message --- .../runtime/src/internal/CustomTemplates/setupTemplateProxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts b/packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts index 7406779362..e24798d3de 100644 --- a/packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts +++ b/packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts @@ -58,7 +58,7 @@ export function setupTemplateProxy( if (slotProxies && slotted) { throw new Error( - `Can not have proxied slot ref when the parent has a slot element child, check your template "${hostBrick.type}" and ref "${ref}"` + `Can not have proxied slot ref when the ref target has a slot element child, check your template "${hostBrick.type}" and ref "${ref}"` ); } From 4e8953fc4e764c2673d5e589ad79eba01c30635e Mon Sep 17 00:00:00 2001 From: weareoutman Date: Wed, 30 Oct 2024 11:50:49 +0800 Subject: [PATCH 3/3] fix(): handle data changes during postAsyncRender --- .../runtime/src/internal/Renderer.spec.ts | 2 +- packages/runtime/src/internal/Renderer.ts | 58 +++++++++++++------ .../src/internal/secret_internals.spec.ts | 4 ++ 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/packages/runtime/src/internal/Renderer.spec.ts b/packages/runtime/src/internal/Renderer.spec.ts index 90217b9438..6ba48e12e8 100644 --- a/packages/runtime/src/internal/Renderer.spec.ts +++ b/packages/runtime/src/internal/Renderer.spec.ts @@ -3447,7 +3447,7 @@ describe("renderBrick for tpl", () => { {} ) ).rejects.toMatchInlineSnapshot( - `[Error: Can not have proxied slot ref when the parent has a slot element child, check your template "my.tpl-m" and ref "main"]` + `[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"]` ); }); }); diff --git a/packages/runtime/src/internal/Renderer.ts b/packages/runtime/src/internal/Renderer.ts index 147b000d5e..fb91429b2e 100644 --- a/packages/runtime/src/internal/Renderer.ts +++ b/packages/runtime/src/internal/Renderer.ts @@ -503,10 +503,26 @@ async function legacyRenderBrick( } }; - const renderControlNode = async ( - runtimeContext: RuntimeContext, - type: "initial" | "rerender" - ) => { + type RenderControlNodeOptions = + | { + type: "initial"; + runtimeContext: RuntimeContext; + tplStateStoreScope?: undefined; + formStateStoreScope?: undefined; + } + | { + type: "rerender"; + runtimeContext: RuntimeContext; + tplStateStoreScope: DataStore<"STATE">[]; + formStateStoreScope: DataStore<"FORM_STATE">[]; + }; + + const renderControlNode = async ({ + type, + runtimeContext, + tplStateStoreScope, + formStateStoreScope, + }: RenderControlNodeOptions) => { let changedAfterInitial = false; const tracker: InitialTracker = { disposes: [], @@ -531,6 +547,16 @@ async function legacyRenderBrick( tracker, uninitialized && type === "initial" ); + + // Changes may happen during `postAsyncRender`. + if (!changedAfterInitial && type === "rerender") { + const scopedStores = [...tplStateStoreScope, ...formStateStoreScope]; + await postAsyncRender(rawOutput, runtimeContext, [ + runtimeContext.ctxStore, + ...scopedStores, + ]); + } + tracker.disposes.forEach((dispose) => dispose()); tracker.disposes.length = 0; uninitialized = false; @@ -549,7 +575,10 @@ async function legacyRenderBrick( return rawOutput!; }; - const controlledOutput = await renderControlNode(runtimeContext, "initial"); + const controlledOutput = await renderControlNode({ + type: "initial", + runtimeContext, + }); const { onMount, onUnmount } = brickConf.lifeCycle ?? {}; @@ -561,17 +590,12 @@ async function legacyRenderBrick( const [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] = createScopedRuntimeContext(runtimeContext); - const reControlledOutput = await renderControlNode( - scopedRuntimeContext, - "rerender" - ); - - const scopedStores = [...tplStateStoreScope, ...formStateStoreScope]; - await postAsyncRender( - reControlledOutput, - scopedRuntimeContext, - scopedStores - ); + const reControlledOutput = await renderControlNode({ + type: "rerender", + runtimeContext: scopedRuntimeContext, + tplStateStoreScope, + formStateStoreScope, + }); // Ignore stale renders if (renderId === currentRenderId) { @@ -596,7 +620,7 @@ async function legacyRenderBrick( )(new CustomEvent("mount", { detail: { rerender: true } })); } - for (const store of scopedStores) { + for (const store of [...tplStateStoreScope, ...formStateStoreScope]) { store.mountAsyncData(); } } diff --git a/packages/runtime/src/internal/secret_internals.spec.ts b/packages/runtime/src/internal/secret_internals.spec.ts index 1ee4af8048..a9e02db319 100644 --- a/packages/runtime/src/internal/secret_internals.spec.ts +++ b/packages/runtime/src/internal/secret_internals.spec.ts @@ -267,6 +267,9 @@ describe("useBrick", () => { }); test("tpl", async () => { + mockInternalApiGetRuntimeContext.mockReturnValue({ + ctxStore: new DataStore("CTX"), + } as RuntimeContext); consoleInfo.mockReturnValue(); customTemplates.define("my.tpl-a", { state: [ @@ -472,6 +475,7 @@ describe("useBrick", () => { unmountUseBrick(renderResult, mountResult); consoleInfo.mockReset(); + mockInternalApiGetRuntimeContext.mockReturnValue(undefined); }); test("root as portal", async () => {