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

fix(dom-expressions): handle expression in ref #317

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

mdynnl
Copy link
Contributor

@mdynnl mdynnl commented Apr 19, 2024

fixes solidjs/solid#2137

these are still relevant here so didn't touch them

let refTarget;
const template8 = <div ref={refTarget} />;
const template10 = <div ref={refFactory()} />;

not sure why the check for call expression was there though.

@SarguelUnda
Copy link

Posting here to not flood the issue we came from.

As a general case I understand your point. I was today year old when I realised that props?.ref isn't lhs aswell.

Isn't there an argument to transform props?.ref into props.ref to get the optimisation of the lvalcond instead of the more general use function that your merge request propose ?

@SarguelUnda
Copy link

Moreover if props.ref is not à function your fix doesn't work either no ?

@mdynnl
Copy link
Contributor Author

mdynnl commented Apr 19, 2024

transforms to

const template10 = (() => {
var _el$16 = _tmpl$4();
var _ref$3 = refFactory();
typeof _ref$3 === "function" && _$use(_ref$3, _el$16);
return _el$16;
})();

and because of this

} else if (t.isCallExpression(value.expression)) {

it only works for a call expression,

but it should work for anything that isn't a literal, let variable, member expression.

@ryansolid
Copy link
Owner

Yeah I think you are right. I probably was fixing a specific issue and was looking too narrow. That being said the fact this change hasn't changed the output of any tests suggests to me are definitely missing some tests we should have.

@mdynnl mdynnl force-pushed the fix/ref-expression branch 4 times, most recently from 94e9e49 to 3a4acab Compare April 22, 2024 15:50
@ryansolid
Copy link
Owner

Thank you for adding the tests. Much appreciated.

@ryansolid ryansolid merged commit 46089d7 into ryansolid:main Apr 22, 2024
2 checks passed
@mdynnl mdynnl deleted the fix/ref-expression branch April 23, 2024 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refs don't work when optional on a component
3 participants