Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with tracking components for client-reorder await tags #1375

Merged
merged 1 commit into from Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/compiler/ast/Node.js
Expand Up @@ -109,10 +109,10 @@ class Node {
*/
makeContainer(array) {
if (array instanceof Container) {
return array;
}

if (!Array.isArray(array) && array instanceof Node) {
const container = array;
array = container.items;
container.items = [];
} else if (!Array.isArray(array) && array instanceof Node) {
array = [array];
}

Expand Down
12 changes: 0 additions & 12 deletions src/core-tags/components/init-components-tag.js
Expand Up @@ -5,17 +5,6 @@ const INIT_COMPONENTS_KEY = Symbol();
const writeInitComponentsCode = require("../../runtime/components")
.writeInitComponentsCode;

const ComponentsContext = require("../../runtime/components/ComponentsContext");

function handleAwaitBeforeRender(eventArgs) {
if (eventArgs.clientReorder) {
const asyncFragmentOut = eventArgs.out;
asyncFragmentOut.___components = new ComponentsContext(
asyncFragmentOut
);
}
}

function handleAwaitFinish(eventArgs) {
const asyncFragmentOut = eventArgs.out;
writeInitComponentsCode(asyncFragmentOut, asyncFragmentOut, false);
Expand All @@ -26,7 +15,6 @@ module.exports = function render(input, out) {
if (outGlobal[INIT_COMPONENTS_KEY] === undefined) {
outGlobal[INIT_COMPONENTS_KEY] = true;

out.on("await:beforeRender", handleAwaitBeforeRender);
out.on("await:finish", handleAwaitFinish);

if (out.isSync() === true) {
Expand Down
11 changes: 2 additions & 9 deletions src/runtime/components/legacy/renderer-legacy.js
Expand Up @@ -5,25 +5,18 @@ var componentLookup = componentsUtil.___componentLookup;
var registry = require("../registry");
var modernRenderer = require("../renderer");
var resolveComponentKey = modernRenderer.___resolveComponentKey;
var handleBeginAsync = modernRenderer.___handleBeginAsync;
var trackAsyncComponents = modernRenderer.___trackAsyncComponents;
var beginComponent = require("../beginComponent");
var endComponent = require("../endComponent");
var w10NOOP = require("warp10/constants").NOOP;

var WIDGETS_BEGIN_ASYNC_ADDED_KEY = "$wa";

function createRendererFunc(templateRenderFunc, componentProps) {
var typeName = componentProps.___type;
//var assignedId = componentProps.id;
var isSplit = componentProps.___split === true;

return function renderer(input, out, assignedId, renderingLogic) {
var outGlobal = out.global;

if (!outGlobal[WIDGETS_BEGIN_ASYNC_ADDED_KEY]) {
outGlobal[WIDGETS_BEGIN_ASYNC_ADDED_KEY] = true;
out.on("beginAsync", handleBeginAsync);
}
trackAsyncComponents(out);

var widgetBody = input.renderBody;
var widgetState = input.widgetState;
Expand Down
30 changes: 20 additions & 10 deletions src/runtime/components/renderer.js
Expand Up @@ -20,6 +20,16 @@ function resolveComponentKey(key, parentComponentDef) {
}
}

function trackAsyncComponents(out) {
if (out.isSync() || out.global[COMPONENT_BEGIN_ASYNC_ADDED_KEY]) {
return;
}

out.on("beginAsync", handleBeginAsync);
out.on("beginDetachedAsync", handleBeginDetachedAsync);
out.global[COMPONENT_BEGIN_ASYNC_ADDED_KEY] = true;
}

function handleBeginAsync(event) {
var parentOut = event.parentOut;
var asyncOut = event.out;
Expand All @@ -40,6 +50,13 @@ function handleBeginAsync(event) {
);
}

function handleBeginDetachedAsync(event) {
var asyncOut = event.out;
handleBeginAsync(event);
asyncOut.on("beginAsync", handleBeginAsync);
asyncOut.on("beginDetachedAsync", handleBeginDetachedAsync);
}

function createRendererFunc(
templateRenderFunc,
componentProps,
Expand All @@ -54,14 +71,7 @@ function createRendererFunc(
var shouldApplySplitMixins = isSplit;

return function renderer(input, out) {
var outGlobal = out.global;

if (out.isSync() === false) {
if (!outGlobal[COMPONENT_BEGIN_ASYNC_ADDED_KEY]) {
outGlobal[COMPONENT_BEGIN_ASYNC_ADDED_KEY] = true;
out.on("beginAsync", handleBeginAsync);
}
}
trackAsyncComponents(out);

var componentsContext = getComponentsContext(out);
var globalComponentsContext = componentsContext.___globalContext;
Expand Down Expand Up @@ -196,7 +206,7 @@ function createRendererFunc(
}
}

component.___global = outGlobal;
component.___global = out.global;

emitLifecycleEvent(component, "render", out);
}
Expand Down Expand Up @@ -231,4 +241,4 @@ module.exports = createRendererFunc;

// exports used by the legacy renderer
createRendererFunc.___resolveComponentKey = resolveComponentKey;
createRendererFunc.___handleBeginAsync = handleBeginAsync;
createRendererFunc.___trackAsyncComponents = trackAsyncComponents;
4 changes: 4 additions & 0 deletions src/runtime/html/AsyncStream.js
Expand Up @@ -469,6 +469,10 @@ var proto = (AsyncStream.prototype = {
var newOut = new AsyncStream(this.global);
// Forward error events to the parent out.
newOut.on("error", this.emit.bind(this, "error"));
this._state.events.emit("beginDetachedAsync", {
out: newOut,
parentOut: this
});
return newOut;
},

Expand Down