-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conversation
Triaged - we definitely want this if it works! Whoever reviews: please double-check (probably by just putting in a breakpoint) that the code is properly hit for a normal navigation, and run the live dev unit tests. |
Unit test added (I may add another one). We should propably take a look at these agents'
|
Ready for review now. |
@SAplayer This is definitely an improvement. I played around with your test page, and the one thing that I saw that wasn't working like I expected was when I edited simpleShared.css -- only the iframe rendering is updated in browser, but that may be a fact of life. I also saw some messages in console that need to be investigated:
I don't think this is ready to merge for Release 0.41, but should be able to get it in soon. |
Ah, I see. |
@redmunds I found the issue causing the CSS problem: |
@redmunds I just managed to fix the Live CSS issue by doing the major changes described above - will investigate the other two now (but it looks like bug # 3 is intermediate...) |
@@ -109,7 +109,8 @@ define(function CSSDocumentModule(require, exports, module) { | |||
*/ | |||
CSSDocument.prototype.getSourceFromBrowser = function getSourceFromBrowser() { | |||
var deferred = new $.Deferred(), | |||
styleSheetId = this._getStyleSheetHeader().styleSheetId, | |||
styleSheetHeader = this._getStyleSheetHeader(), | |||
styleSheetId = styleSheetHeader[_.keys(styleSheetHeader)[0]].styleSheetId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether there's a nicer method to determinate the first index of an object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know this code well enough to know what it's trying to do, but just wanted to point out that there's no concept of "first" (or "index" for that matter) in associative arrays -- the keys are unordered. I'm guessing this code is assuming only one key exists, and it just wants its value, but it doesn't know what the one key is...
If that's the case, you could do it more efficiently with a utiltiy like this:
function getOnlyValue(obj) {
for (var key in obj) {
if (_.has(obj, key)) return obj[key];
}
}
Or, to fail fast when the single-key assumption is wrong:
function getOnlyValue(obj) {
var foundKey;
for (var key in obj) {
if (_.has(obj, key)) {
if (foundKey) throw new Error("Object has multiple keys: " + key + ", " + foundKey);
foundKey = key;
}
}
return obj[foundKey];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it can have multiple values (that's what this PR is all about - we assumed it can only have one value before), but they should all be the same, so it doesn't matter much which one to use. And as they are enumerated (but not beginning with 0), the first one should be ok...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SAplayer When you say "they are enumerated (but not beginning with 0)," do you mean the keys are all numbers, but they're non-sequential?
If so, still bear in mind that there's no guarantee on the order of Object.keys() -- the lowest number is not necessarily first in the array. If your code relies on always getting the lowest index/key, you should .sort() the keys array to ensure that'll always actually happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's how the array is structured.
I don't need to have the first entry, AFAIK every entry should have the same value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's safe accessing [0]
. I think @peterflynn 's first suggestion should work (with a change to make jslint happy):
function getOnlyValue(obj) {
for (var key in obj) {
if (_.has(obj, key)) {
return obj[key];
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcelgerber You still haven't fixed this line.
@redmunds It looks like our whole DOMAgent, or maybe even the Inspector, isn't made for iframe updates, or would at least need some major changes. I guess it's not worth it - what's your opinion? |
There's work being done to totally change how Live Preview works, so it's definitely not worth putting a lot of effort into this. |
Fine. As stated above, it isn't even common. When implementing this, we should be aware of what to pay attention on. |
Yes, that's the Trello Card. |
@SAplayer Is this PR worth merging, or should it be closed? |
It will improve the experience quite a lot, so yes, it's worth merging. |
} | ||
|
||
/** | ||
* Get a style sheet for a url | ||
* @param {string} url | ||
* @return {CSS.CSSStyleSheetHeader} | ||
* @return {Array} Array of CSSStyleSheetHeaders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be:
* @return {Array.<CSSStyleSheetHeader>}
|
||
var i, rule, from, to; | ||
for (i in res.matchedCSSRules) { | ||
rule = res.matchedCSSRules[i]; | ||
if (rule.ruleId && rule.ruleId.styleSheetId === styleSheetId) { | ||
if (rule.ruleId && styleSheetIds && styleSheetIds[rule.ruleId.styleSheetId]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
styleSheetIds
is an Object, so it doesn't need to be checked for null
.
@redmunds Changes pushed. I've also unified |
} | ||
|
||
/** | ||
* Reload a CSS style sheet from a document | ||
* @param {Document} document | ||
* @param {?string=doc.getText()} new content of every stylesheet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually wonder if it's a valid JSDoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param {?string=doc.getText()} new content of every stylesheet
Not valid. Where do you see that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param {?string} new content of every stylesheet. Defaults to doc.getText() if omitted
Is this valid then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's optional, it should be the following. Also, param name was missing.
* @param {string=} newContent new content of every stylesheet. Defaults to doc.getText() if omitted
FYI: https://developers.google.com/closure/compiler/docs/js-for-compiler
I've been playing around with the simple1iframe.html test file trying to see the difference between this branch and master. The only difference I see is that changing the bg color in simpleShared.css changes only the iframe in master, but entire page in your branch. Can you post a couple recipe that illustrates this fixing #7935 and #7785 ? |
Result: The page doesn't change Take a look at the DevTools console: Multiple error messages logged So basically, the outer HTML won't reflect any CSS changes any more (at least unless you press |
Thanks for the recipe. I think I didn't see that because I was switching to iframe.html between those 2 files. |
@redmunds Changes pushed again. |
return obj[key]; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't noticed this before, but this function should explicitly return null;
at the end in case it falls out of the for
loop (instead of implicitly returning undefined
.).
Done with review. A couple more comments. |
@redmunds Changes pushed once again. |
Thanks! Merging. |
Fix Live CSS with an iframe element
For #7935 and #7785
Bugs to fix: