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

Isodata #38

Open
vavrecan opened this issue Aug 30, 2024 · 11 comments
Open

Isodata #38

vavrecan opened this issue Aug 30, 2024 · 11 comments

Comments

@vavrecan
Copy link

vavrecan commented Aug 30, 2024

Hello, why is isodata created?
preactjs/wmr#592
https://github.com/preactjs/preact-iso/blob/main/src/prerender.js#L37
Thank you

@rschristian
Copy link
Member

Right now, it's primarily for hydrate to determine whether to hydrate or render.

As mentioned, we had some discussions internally a few years back, I'm not sure if we ever fully decided on what we wanted to do.

@vavrecan
Copy link
Author

vavrecan commented Aug 30, 2024 via email

@rschristian
Copy link
Member

May I ask why? And what should be configurable?

@vavrecan
Copy link
Author

The "subtype" must always be included in the "type," just as "mimetype" is required - https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type

Error: Bad value isodata for attribute type on element script: Subtype missing.
From line 1, column 1; to line 1, column 23

<script type="isodata">

@rschristian
Copy link
Member

The "subtype" must always be included in the "type," just as "mimetype" is required

That's more of a suggestion than a legitimate requirement. This is pretty standard, for good or bad.

@vavrecan
Copy link
Author

vavrecan commented Aug 30, 2024 via email

@rschristian
Copy link
Member

rschristian commented Aug 30, 2024

Sorry, but we target browsers, not spec validators.

We can try to change this in the future, in a major, but adhering to specs isn't really a project goal. What browsers do > what specs say they should do, and as I far as I'm aware no browser has any issue with this.

@vavrecan
Copy link
Author

vavrecan commented Aug 30, 2024

Thank you for the clarification! I ended up writing my own prerender and hydrate methods. This allowed me to store the props data directly in <script> tags, so now all props are available in the HTML. This way, the data props don't have to be loaded from external js, and I can modify them server-side if needed

<div id="app"><div>Hello world</div><script type="application/json" id="isodata" data-route="/product">{"title":"hello world"}</script></div>

It would be great if the library had an option to save props data into isodata script tags, so this could be done more easily.

@rschristian
Copy link
Member

Glad to hear it!

It would be great if the library had an option to save props data into isodata script tags, so this could be done more easily.

We'll probably support that via @preact/preset-vite instead, in the same API we used for WMR. I don't think that's something this, as a thin wrapper around RTS, necessarily needs to be aware of.

@vavrecan
Copy link
Author

That's perfect! I'm also using preact/preset-vite atm

@rschristian
Copy link
Member

Great!

I didn't originally copy it over as I wasn't quite sure where we wanted it (especially with preact-iso being separated out, as it was more tightly-bound to WMR), but never circled back around to that. Will try to get it added soon though. It'll be a data key on the return object, i.e.,

export async function prerender(data) {
    ...
    return { html, data: { title: 'Hello World!' } };
}

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

2 participants