Skip to content

Commit

Permalink
fix: issue with data-marko attributes under 'no-update' with <await>
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Apr 30, 2020
1 parent f793a99 commit 1cab05a
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 19 deletions.
13 changes: 8 additions & 5 deletions packages/marko/src/compiler/ast/HtmlElement/html/StartTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class StartTag extends Node {
var attributes = this.attributes;

if (this.includeDataMarko) {
var dataMarkoArgs = [];
var dataMarkoArgs = [
builder.identifier("out"),
builder.identifier("__component")
];

var properties = this.properties;
if (properties) {
Expand All @@ -48,14 +51,14 @@ class StartTag extends Node {
}

if (this.userKey) {
if (dataMarkoArgs.length === 0) {
dataMarkoArgs.push(builder.literal(null));
if (dataMarkoArgs.length === 2) {
dataMarkoArgs.push(builder.literal(0));
}

dataMarkoArgs.push(this.userKey, builder.identifier("__component"));
dataMarkoArgs.push(this.userKey);
}

if (dataMarkoArgs.length) {
if (dataMarkoArgs.length > 2) {
nodes.push(
builder.html(
builder.functionCall(context.helper("dataMarko"), dataMarkoArgs)
Expand Down
4 changes: 2 additions & 2 deletions packages/marko/src/runtime/html/AsyncStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ var proto = (AsyncStream.prototype = {
var str =
"<" +
tagName +
markoAttr(props, key, componentDef) +
markoAttr(this, componentDef, props, key) +
attrsHelper(elementAttrs) +
">";

Expand Down Expand Up @@ -533,7 +533,7 @@ var proto = (AsyncStream.prototype = {
var str =
"<" +
name +
markoAttr(props, key, componentDef) +
markoAttr(this, componentDef, props, key) +
attrsHelper(elementAttrs) +
">";

Expand Down
7 changes: 3 additions & 4 deletions packages/marko/src/runtime/html/helpers/data-marko.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ var FLAG_WILL_RERENDER_IN_BROWSER = 1;
// var FLAG_IS_LEGACY = 4;
// var FLAG_OLD_HYDRATE_NO_CREATE = 8;

module.exports = function dataMarko(props, key, componentDef) {
module.exports = function dataMarko(out, componentDef, props, key) {
var result = "";
var willNotRerender =
!componentDef ||
out.___components.___isPreserved ||
(componentDef.___renderBoundary &&
(componentDef.___flags & FLAG_WILL_RERENDER_IN_BROWSER) === 0) ||
componentDef.___componentsContext.___isPreserved;
(componentDef.___flags & FLAG_WILL_RERENDER_IN_BROWSER) === 0);

if (willNotRerender) {
if (props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ function render(input, out, __component, component, state) {
var data = input;

out.w("<div><input" +
marko_dataMarko({
marko_dataMarko(out, __component, {
noupdate: [
"value"
]
}) +
marko_attr("value", input.defaultValue) +
"><input" +
marko_dataMarko({
marko_dataMarko(out, __component, {
noupdate: [
"value"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function render(input, out, __component, component, state) {
var data = input;

out.w("<input" +
marko_dataMarko({
marko_dataMarko(out, __component, {
noupdate: [
"value"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function render(input, out, __component, widget, component) {
var data = input;

out.w("<div" +
marko_dataMarko(null, "@_wbind", __component) +
marko_dataMarko(out, __component, 0, "@_wbind") +
" data-widget=/marko-test$1.0.0/components-compilation/fixtures-html-deprecated/bind-component/index" +
marko_attr("id", __component.elId()) +
"></div>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function render(input, out, __component, widget, component) {
var data = input;

out.w("<div" +
marko_dataMarko(null, "@_wbind", __component) +
marko_dataMarko(out, __component, 0, "@_wbind") +
" data-widget=/marko-test$1.0.0/components-compilation/fixtures-html-deprecated/bind-widget/widget" +
marko_attr("id", __component.elId()) +
"></div>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function render(input, out, __component, widget, component) {
var data = input;

out.w("<div" +
marko_dataMarko(null, "@_wbind", __component) +
marko_dataMarko(out, __component, 0, "@_wbind") +
" data-widget=/marko-test$1.0.0/components-compilation/fixtures-html-deprecated/component-include-attr/index" +
marko_attr("id", __component.elId()) +
"><h1>Header</h1><div>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function render(input, out, __component, widget, component) {
var data = input;

out.w("<div" +
marko_dataMarko(null, "@_wbind", __component) +
marko_dataMarko(out, __component, 0, "@_wbind") +
" data-widget=/marko-test$1.0.0/components-compilation/fixtures-html-deprecated/component-template-entry/component" +
marko_attr("id", __component.elId()) +
"></div>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function render(input, out, __component, widget, component) {
__component.t(marko_componentTypes[data.isMobile ? "default" : "mobile"]);

out.w("<div" +
marko_dataMarko(null, "@_wbind", __component) +
marko_dataMarko(out, __component, 0, "@_wbind") +
"></div>");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!--F#p_abc--><button data-marko='{"onclick":"handleClick s0 false"}' data-marko-key="@abc s0">Click Me</button><!--F/-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<await(data.promiseData)>
<@then>
<button key="abc" no-update on-click("handleClick")>
Click Me
</button>
</@then>
</await>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.templateData = {
promiseData: Promise.resolve("Test promise")
};

exports.skip_vdom = "This test is only used to test the hydrate boundaries.";

0 comments on commit 1cab05a

Please sign in to comment.