diff --git a/layout/style/crashtests/1356601-1.html b/layout/style/crashtests/1356601-1.html
new file mode 100644
index 000000000..6db6ad1fe
--- /dev/null
+++ b/layout/style/crashtests/1356601-1.html
@@ -0,0 +1,18 @@
+
+
+
+
+ Crash
+
+
diff --git a/layout/style/crashtests/crashtests.list b/layout/style/crashtests/crashtests.list
index 0cca3be99..e2b9d914c 100644
--- a/layout/style/crashtests/crashtests.list
+++ b/layout/style/crashtests/crashtests.list
@@ -136,3 +136,4 @@ load border-image-visited-link.html
load font-face-truncated-src.html
load large_border_image_width.html
load long-url-list-stack-overflow.html
+load 1356601-1.html
diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp
index b82a94317..299b2e434 100644
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -2364,9 +2364,23 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID,
if (!highestNode)
highestNode = rootNode;
- if (!ruleData.mConditions.CacheableWithoutDependencies())
- detail = eRulePartialMixed; // Treat as though some data is specified to avoid
- // the optimizations and force data computation.
+ MOZ_ASSERT(!(aSID == eStyleStruct_Variables && startStruct),
+ "if we start caching Variables structs in the rule tree, then "
+ "not forcing detail to eRulePartialMixed just below is no "
+ "longer valid");
+
+ if (!ruleData.mConditions.CacheableWithoutDependencies() &&
+ aSID != eStyleStruct_Variables) {
+ // Treat as though some data is specified to avoid the optimizations and
+ // force data computation.
+ //
+ // We don't need to do this for Variables structs since we know those are
+ // never cached in the rule tree, and it avoids wasteful computation of a
+ // new Variables struct when we have no additional variable declarations,
+ // which otherwise could happen when there is an AnimValuesStyleRule
+ // (which calls SetUncacheable for style contexts with pseudo data).
+ detail = eRulePartialMixed;
+ }
if (detail == eRuleNone && startStruct) {
// We specified absolutely no rule information, but a parent rule in the tree