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

Bad id created when using "no-update" and scoped id together #1664

Open
msendlakowski opened this issue Feb 22, 2021 · 3 comments
Open

Bad id created when using "no-update" and scoped id together #1664

msendlakowski opened this issue Feb 22, 2021 · 3 comments
Labels
type:unverified bug A bug report that has not been verified

Comments

@msendlakowski
Copy link

Marko Version: x.x.x

5.1.10

Details

If you use "no-update" on a scoped form element, the id of the element isn't correct.
The following marko will generate an id of "s0-0-0-13-s0-0-0-13-input1"

<input id:scoped="input1" no-update />

I don't know if this is a huge issue other than the fact that if I use a "for" tag on a label, the for tag uses "s0-0-0-13-input1", so doesn't match.

Expected Behavior

The id should be s0-0-0-13-input1 or at least should be matched by the "for".

<label for:scoped="input1">Input</label>
<input id:scoped="input1" no-update />

should generate:

<label for="s0-0-0-13-input1">Input</label>
<input id="s0-0-0-13-input1">

Actual Behavior

<label for="s0-0-0-13-input1">Input</label>
<input id="s0-0-0-13-s0-0-0-13-input1">

Possible Fix

Additional Info

Your Environment

Node v14.15..4
Chrome v88
Desktop

Steps to Reproduce

<label for:scoped="input1">Input</label>
<input id:scoped="input1" no-update />

Stack Trace

@msendlakowski msendlakowski added the type:unverified bug A bug report that has not been verified label Feb 22, 2021
@taylor-hunt-kr
Copy link

I messed around with your repro case in Try Online, but could only conclude a few things:

  • The “Compiled (HTML)” looks like something is clearly goofy with nested _component.elId’s:

     out.w(
       `<label${_marko_attr("for", _component.elId("input1"))}>Input</label>`
     );
     // …
     out.w(
             `<input${_marko_attr(
               "id",
               _component.elId(_component.elId("input1"))
             )}>`
           );

    “Compiled (VDOM)” shows the same problem.

  • Adding no-update to the <label> makes the IDs match

  • I can’t seem to chain :scoped and :no-update on the same attribute, so I can’t tell if for:scoped:no-update would also make the IDs match

@egavrilov
Copy link

egavrilov commented Feb 27, 2023

The issue is in copying the attributes inside no-update modifier:

importDefault(file, "marko/src/runtime/vdom/preserve-attrs");

If the no-update modifier comes first than scoped attribute has correct value:

<label for:scoped="input1">Input</label>
<input no-update id:scoped="input1" />

@AndresBarreto-code
Copy link

AndresBarreto-code commented Jul 25, 2023

I had the same issue, using id:scoped= and no-update directives creates a completely different id than expected.

My solution was using no-update-body instead of no-update, it worked for me for the elements I was using.

    <h2
      id:scoped="idString"
      no-update-body
    >
      ${state.initialState}
    </h2>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:unverified bug A bug report that has not been verified
Projects
None yet
Development

No branches or pull requests

4 participants