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

render is not defined when importing solid-js/web as a namespace #158

Open
thetarnav opened this issue Sep 26, 2023 · 6 comments
Open

render is not defined when importing solid-js/web as a namespace #158

thetarnav opened this issue Sep 26, 2023 · 6 comments

Comments

@thetarnav
Copy link

Using render from solid-js/web when it is imported as a namespace

import * as solid_web from "solid-js/web"

solid_web.render(() => <App/>, root)

causes an error:

Uncaught ReferenceError: render is not defined

https://playground.solidjs.com/anonymous/aaaa8129-cbf3-4f01-9e67-f9e81f8f094a

@milomg
Copy link
Member

milomg commented Sep 26, 2023

So the reason this happens is because we patch render to set window.dispose with a regex... We replace render( with window.dispose = render(

So in your case the code that is generated is:

import { template as _$template } from "solid-js/web";
import { delegateEvents as _$delegateEvents } from "solid-js/web";
import { createComponent as _$createComponent } from "solid-js/web";
import { insert as _$insert } from "solid-js/web";
const _tmpl$ = /*#__PURE__*/_$template(`<button type="button">`);
import * as solid_web from "solid-js/web";
import * as solid from "solid-js";
function Counter() {
  const [count, setCount] = solid.createSignal(1);
  const increment = () => setCount(count() + 1);
  return (() => {
    const _el$ = _tmpl$();
    _el$.$$click = increment;
    _$insert(_el$, count);
    return _el$;
  })();
}
solid_web.window.dispose = render(() => _$createComponent(Counter, {}), document.getElementById("app"));
_$delegateEvents(["click"]);

I'm not sure what the right strategy is here. Maybe just writing const render = solid_web.render; would help?

@thetarnav
Copy link
Author

yeah I know how to get around this. Just not an obvious error to hit. Maybe something that could be considered when transforming the code

@xpat
Copy link

xpat commented Sep 8, 2024

I got this error when pasting from the Solid tutorial. I tried to troubleshoot const render = solid_web.render; but no luck. Just learning Solid. Any other suggestions?

@milomg

This comment was marked as off-topic.

@xpat

This comment was marked as off-topic.

@milomg
Copy link
Member

milomg commented Sep 9, 2024

@xpat This sounds like an unrelated issue, can you post your question in the SolidJS discord #support channel instead

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

No branches or pull requests

3 participants