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

Kagekiri querySelector not working #95

Open
shivamothkuri opened this issue Apr 12, 2024 · 4 comments
Open

Kagekiri querySelector not working #95

shivamothkuri opened this issue Apr 12, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@shivamothkuri
Copy link
Contributor

shivamothkuri commented Apr 12, 2024

This is my CSS selector
div.filters > div:nth-child(1) select.templateInputs

This works for Puppeteer and devtools element search. But, don't work in Kagekiri

When I digged into the source code, found that this is what happening.

Step1: select.templateInputs has a parent div - which resolves to div.uiInput
Step2: div.uiInput has any direct(because of > selector) parent with div.filters? No. It fails here!

Sample html

<div class="filters runtime_sales_emailtemplateuiTemplateInsertDialog" data-aura-rendered-by="3135:0"
                data-aura-class="runtime_sales_emailtemplateuiTemplateInsertDialog">
                <div>
                    <div class="uiInput uiInputSelect uiInput--default uiInput--select"
                        data-aura-class="uiInput uiInputSelect uiInput--default uiInput--select"><label for="3137:0"
                            class="uiLabel-top form-element__label uiLabel" data-aura-rendered-by="3238:0"
                            data-aura-class="uiLabel"><span id="3137:0-label" title="Templates" class=""
                                data-aura-rendered-by="3239:0">Templates</span></label>

                              <select size="1" aria-describedby="" id="" class="templateInputs select" data-aura-rendered-by="3142:0" data-interactive-lib-uid="14"><!--render facet: 3143:0-->
                                   <option label="My Templates" value="MyLightning">My Templates</option>
                                   <option label="All Templates" value="AllLightning">All Templates</option>
                             </select>
                 </div>
</div>
</div>
@nolanlawson
Copy link
Contributor

Hi @shivamothkuri is there any chance you could provide a minimal reproducible test case using something like stackblitz.com or codepen.io?

@nolanlawson nolanlawson added the bug Something isn't working label Apr 12, 2024
@nolanlawson
Copy link
Contributor

@shivamothkuri Actually scratch that, I threw together a CodePen repro based on your description: https://codepen.io/nolanlawson-the-selector/pen/jORKJvg

It indeed seems to demonstrate that kagekiri does not reproduce the same behavior as document.querySelector. Thank you!

@nolanlawson
Copy link
Contributor

Reduction of the issue:

<div class="filters">
  <div>
    <div>
      <select class="templateInputs"></select>
    </div>
  </div>
</div>
// null
kagekiri.querySelector('div.filters > div:nth-child(1) select.templateInputs')

// <select class="templateInputs"></select>
document.querySelector('div.filters > div:nth-child(1) select.templateInputs')

@nolanlawson
Copy link
Contributor

I think I understand the problem now - basically, as we are matching right-to-left, there is a problem of ambiguity. You can imagine adding multiple layers of <div>s above to reproduce the issue.

Essentially, kagekiri works right-to-left, and when it matches the div:nth-child(1), it continues matching to the left. But since it grabs the nearest div:nth-child(1), which is the one immediately surrounding .templateInputs, it thinks the selector does not match because it "should" have matched the <div> one level higher, whose parent is .filters.

You can imagine the algorithm for this getting fairly nasty, as there is potentially a combinatorial explosion of possibilities that kagekiri has to match against.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants