Skip to content

server side pre-rendered messages shouldn't get shipped to the client #354

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

Open
samuelstroschein opened this issue Jan 30, 2025 · 2 comments
Labels

Comments

@samuelstroschein
Copy link
Member

samuelstroschein commented Jan 30, 2025

Context

If a message is pre-rendered (SSG or SSR), there is no need to ship the message to the client, if the message is static (takes no arguments). See #88 (comment)

// happy_elephant = This is a message in English. 

<p>{m.happy_elephant()}</p>

The HTML is rendered as

<p>This is a message in English</p>

Given that the message is static (takes no arguments like username), there is no need to ship the message function to the client. The message will aways be This is a message in English

Proposal

Figure out how to avoid shipping static messages that are pre-rendered to the client.

@samuelstroschein
Copy link
Member Author

samuelstroschein commented Mar 10, 2025

Tricky one.

The client needs the message for client-side hydration. I have to look into frameworks to see if replacing the expression <p>{m.foo()}</p> with <p></p> will make hydration work because frameworks skip over empty HTML tags. The server would SSR <p></p> as <p>example text</p>

In any case, research in #425 has shown that MPAs (Server side rendering + client side routing like SvelteKit) need to receive the message over the network to render pages.

@samuelstroschein
Copy link
Member Author

I dug into a front-end framework to see how they hydrate. Svelte hydrates the HTML by completely re-rendering it even if the text of an HTML node is static.

<p>Hello world, how are you?</p>
import { a as append, t as template } from "../chunks/C2OGyoPZ.js";
import "../chunks/DmGnqJ7V.js";
+var root = template(`<p>Hello world, how are you?</p>`);
function _page($$anchor) {
  var p = root();
  append($$anchor, p);
}
export {
  _page as component
};

This indicates that even if we optimize messages to be static via an AST transform in a bundler, the optimization has no effect because frameworks load the static text anyways.

In a NextJS project with RSC, no JS is shipped to the client, which makes this optimization redundant and is the first time I understand RSC's value.

What's next? Frameworks need to optimize this themselves it seems like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant