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

Hydration not working when not using self-closing tag #38

Closed
arggh opened this issue Sep 20, 2020 · 5 comments · Fixed by #35
Closed

Hydration not working when not using self-closing tag #38

arggh opened this issue Sep 20, 2020 · 5 comments · Fixed by #35

Comments

@arggh
Copy link

arggh commented Sep 20, 2020

Just starting out with Elderjs, but I ran into a weird issue.

This won't hydrate on the client:

<Map hydrate-client={{}} ></Map>

...but this will:

<Map hydrate-client={{}} />

I'm working with the v0.2.0 template.

@swyxio
Copy link

swyxio commented Sep 20, 2020

the issue is almost certainly with this regex -

const hydrateableComponentPattern = /<([a-zA-Z]+)[^>]+hydrate-client={([^]*?})}[^/>]+\/>/gim;

if i think a little bit its understandable why children are not supported - hard to draw the line between what is hydrated and what isnt.

we should add a regex for the non-self-closing case and insert an error if found, should be quite cheap.

@nickreese
Copy link
Contributor

@arggh / @sw-yx Good calls. :)

We will throw an error during rollup in v1 for <Map hydrate-client={{}} ></Map> style components. Adding this functionality now.

@nickreese nickreese linked a pull request Sep 21, 2020 that will close this issue
34 tasks
@swyxio
Copy link

swyxio commented Sep 21, 2020

ok nice. just note that people might try to insert children in those components too, so the regex may have to accommodate that (i honestly dont know if this is possible) and optionally give a nice reason why we dont allow children in hydrated components

@nickreese
Copy link
Contributor

nickreese commented Sep 21, 2020

@sw-yx

Here is the improved error text:

Elder.js only supports self-closing syntax on hydrated components. This means <Foo /> not <Foo></Foo> or <Foo>Something</Foo>. Offending component: ${offendingCode}. Slots and child components aren't supported during hydration as it would result in huge HTML payloads. If you need this functionality try wrapping the offending component in a parent component without slots or child components and hydrate that.

@swyxio
Copy link

swyxio commented Sep 21, 2020

love it

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 a pull request may close this issue.

3 participants