question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Version bump from 8.0.9 to 8.1.0 causes infinite loop with `next()`

See original GitHub issue

Summary

I’ve written a postcss plugin that works well in 8.0.9, but runs into an infinite loop on 8.1.0 (as well as 8.1.4). I’m currently unable to find the cause (or whether I’m using anything that’s not explicitly in the postcss api that would warrant this issue).

Failing code

The lines of the plugin that are causing an infinite loop are:

while (
  // Should go after initial comments and existing variable declarations
  shouldGoAfter(decl, beforeNode) 
) {
  beforeNode = beforeNode.next();
}

and the minimal failing test case I can produce is the following:

.toggle-checkbox {
  $height: 15px;
  $width: 50px;

  &-slider {
    &:hover {
      height: $height;
      width: $width;
    }
  }
}

Additional Context:

  • I’m using poscss-scss as the parser (version 3.0.2 when running with postcss 8.1.0+)
  • Currently testing on node 10.18.1

What I’ve looked at so far

The crux of the bug appears to be that decl.next() === decl is true. This appears to be after $height has moved up to root, but this didn’t seem to happen before 8.1.0.

I’ve looked through the release diff https://github.com/postcss/postcss/compare/8.0.9...8.1.0 and haven’t seen anything that might cause something similar to this, but did notice a subtle difference in behavior with markDirty.

Next steps

I’ll do some more work a little later on getting a simpler plugin to reproduce the infinite loop, and for now I’ll set an exact dependency on 8.0.9.

I’m curious if there’s either a known or expected scenario where a node’s next() would become itself, resulting in this loop. Also not sure if this is more closely related to postcss-scss instead.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
aicommented, Oct 29, 2020

It happens, because in 8.1 we fixed an issue and now Root is calling on any node’s changes.

https://twitter.com/PostCSS/status/1310217954953490435

You have a problem in child.prop.startsWith('$') where you do not check that you already applied changes.

There are a few options to fix the plugin:

  1. Move to correct Declaration and Rule listeners and check that node was already processed.
  2. Use Once instead of Root.
1reaction
aicommented, Oct 28, 2020

Can you try to replace here:

      get (node, prop) {
        if (prop === 'proxyOf') {
          return node
-       } else if (prop === 'root') {
-         return () => node.root().toProxy()
+      } else if (prop === 'root' || prop === 'next' || prop === 'prev') {
+         return () => node[prop]().toProxy()
Read more comments on GitHub >

github_iconTop Results From Across the Web

PHP 8 ChangeLog
Version 8.2.0. 08 Dec 2022. CLI: Fixed bug #81496 (Server logs incorrect request method). Updated the mime-type table for the builtin-server.
Read more >
Changelog - Cypress Documentation
Fixed an issue that could lead to infinite recursion and thus a crash when running tests that make use of cy.intercept() . Fixes...
Read more >
Change Log - Trumpet, Inc
We have found a regression issue introduced in version 5.2.26 that can (in some rare cases) result in corrupted S-OCR database indexes. This...
Read more >
RowSetIterator next() never returns null, causing infinite loop
I'm using JDeveloper 11.1.1.6. One tricky issue we found is looping through a view object using RowSetIterator. next() of RowSetIterator ...
Read more >
Search Results - CVE
It is possible to trigger the infinite loop by crafting a certificate that has invalid ... 8.0 versions before 8.0.9, and 8.1 versions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found