Repository navigation
RPC answers bring the stylesheets of the elements in them - #16
Merged
Merged
Conversation
RpcServer.respond takes ~assets, as Page.respond does, and encodes the answer with their styles, so an element an RPC returns sends the C rows its classes need. The client's call already waits for them (valueFromStream holds the root back until its sheets load). weft_shop's cards gain a sale badge with a sheet of its own, which "Load more" brings on a page that hasn't loaded it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
RPC answers now bring their stylesheets. Before,
RpcServerencoded an RPC's result withoutRender'sstyles, so an element it returned (weft_shop's "Load more" cards) was styled only by the sheets the page had already loaded: a class from any other sheet showed unstyled. This is follow-up 1 ofdocs/weft_css_plan.md, now marked done with an "As built" note.weft_serverRpcServer.respondtakes~assets(virtual:weft/assets, asPage.responddoes), and encodes the answer with their styles: theCrows of what it renders go before the rows needing them, as in a page's payload. Without~assets, nothing changes.Rpc.calldecodes withDecoder.valueFromStream, which already holds the root back until its sheets load. So the call resolves only once they have, and whatever the caller renders with the answer is styled; a later row (a card's stock) waits as any other does.Page.stylesOfis public: the stylesheets in an app's assets, asRendertakes them.respondrather thanrouter, so the module listing the handlers needn't import them.Examples
weft_shopandweft_notespass~assetsto their RPC route.weft_shop's product cards have a sale badge ("20% off") in a file of its own (SaleBadge), with its own sheet, which a page sends only if something on it is on sale.Testing
weft_server'sSheets_test, "RPCs, with sheets": through the router in process, an answer whose element has a class from an unloaded sheet is held back until that sheet loads; a boundary in an answer keeps its fallback, after the call has resolved, until its later row's sheet loads; without assets, no sheets are sent and nothing waits. The first two fail with the styles left out.weft_shop'sStyles_test: shoes sorted dearest first have nothing on sale on the first page, so the badge's sheet isn't loaded; with it held, "Load more" keeps the grid as it was ("Loading…") until the sheet loads, then shows the cards with their badges, andWeftTesting.unstyledis empty at every step. With~assetstaken out of the route it fails: the cards show at once, unstyled.Checklist
pnpm run check,pnpm run testandpnpm run e2epass (the flash test in Chromium, Firefox and WebKit)pnpm changeset) if a published package changed🤖 Generated with Claude Code