Repository navigation
Let a stream script yield its output a piece at a time (1.0.0-rc.13) - #146
Merged
Merged
Conversation
A data-bascik-stream script written as a generator (export default async function*) now sends each value it yields to the browser as soon as it is yielded, where the script tag was. One script can stream a list row by row from a cursor, a paged API or several calls, where it took one script tag per row before. A generator used to be refused as "[object AsyncGenerator]" and leave an empty slot. - request-execution: a job runner may resolve to an async iterable of chunks (ScriptOutputRunner). The streamer writes each chunk of a stream job as it arrives and pulls the next only after that write resolved; a job ahead of the write cursor is pulled once and waits. Server jobs and buffered responses join the chunks. invokeLoadedWithDeadline takes chunks: true and returns a ScriptChunkSource whose deadline counts only the time a pull is pending, so a slow client does not time a script out. - Node, Cloudflare and Netlify hosts print every yielded value by the rules for a returned one (string, html value, array; scoped class names, ANSI stripping) under the same onServerScriptError policy. A failure part-way keeps the rows already sent. When the client leaves or the script times out, the generator is ended so its finally blocks run. A value the generator returns is sent last. - Request-time component rendering runs per yielded value for a stream job (one stylesheet per response, ids that never repeat across chunks) and on the joined output for a server job. - A typed array is refused as output with a decode hint instead of printing its numbers; a Buffer still prints its text. - Docs: "Yield rows as they arrive" on the Stream Scripts page with recipes for skeleton rows, fastest-first and cleanup; the custom adapter tutorial, the runtime reference, the server internals page and the bascik-scripts skill. A /stream-rows page on both adapter demo sites. - Versions: @bascik/bascik, create-bascik and @bascik/adapter-cloudflare 1.0.0-rc.13, @bascik/adapter-netlify 1.0.0-rc.3. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Shop preview: https://bascik-shop-pr-146.collin-inbox.workers.dev Stripe sandbox payments are enabled. Paid orders create unconfirmed Printful drafts only. Production confirmation and customer email are blocked in test mode. No live domain changes. |
Site PreviewsBuilt from 96e152a on
|
On the /stream-rows demo pages a row that had arrived went dim and solid in turn. The skeleton rows pulse by animating opacity, which makes each one a stacking layer of its own, and layers are painted above ordinary content sharing the same grid cell, so the skeleton showed through on top of the rows. The list of real rows now has its own layer above the skeletons (position: relative; z-index: 1) on both adapter demo pages, in the docs recipe, and in the pkg e2e fixture, whose skeleton rows now pulse too. The demo contract and the pkg stream spec check that the topmost element at the first row's center is the row. The contract's position check now compares the two lists instead of the row, which slides in for a moment. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The adapter tests compile without DOM globals, so a bare `document` in an evaluate callback failed the workspace typecheck. Co-Authored-By: Claude Fable 5.2 <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 this adds
A
data-bascik-streamscript written as a generator sends each value it yields to the browser as soon as it is yielded, where the script tag was:Before this, a generator was refused as
[object AsyncGenerator]and left an empty slot, so streaming a list row by row took one script tag per row.Behavior
htmlvalue, array), gets the component's scoped class names, and may hold component tags, which are rendered as the value is sent.:has()hides a placeholder when the first row lands, and rows can cover skeleton rows one at a time.scripts.onServerScriptError; the rest of the page still streams.scripts.timeoutcounts only the time the script spends producing values, not the time the visitor's connection takes to accept them.finallyblocks run.data-bascik-serverscript may be a generator too: its values are joined before the page is sent, so a failure is still a 500.returnfor an empty list is not lost.bascik --server, the Cloudflare adapter and the Netlify adapter.Two changes to existing behavior
Uint8Array) is refused with a decode hint. It used to print its byte values as comma-separated numbers. A NodeBufferstill prints its text.For adapter authors
@bascik/bascik/runtimegainsScriptOutputRunner(a runner that may resolve to an async iterable of chunks),chunks: trueoninvokeLoadedWithDeadline, andscriptChunkOutput,scriptChunkIteratorandcollectScriptJobOutput. AScriptJobRunnerthat returns strings keeps working unchanged. The custom adapter tutorial's job runner is updated.Docs and demos
bascik --serverrun./stream-rowspage on both adapter demo sites, in the nav, the overview and the shared browser contract. The docs link to it, so those links resolve once this merges and the demo deploys.@bascik/bascik,create-bascikand@bascik/adapter-cloudflare1.0.0-rc.13;@bascik/adapter-netlify1.0.0-rc.3. Changelog section added.Decisions worth a look
yieldand holds that one value until its turn, so adjacent scripts overlap the way returning scripts already do.scripts.renderLimits.maxNestedScripts. Documented, not changed.Tests
request-execution-chunks.test.ts), Node host (server-scripts-chunks.test.ts), component rendering (request-render-chunks.test.ts), output classification, and both adapter runtimes.server-scripts-stream.test.tson the dev, HTTP/1.1 and HTTP/2 lanes (rows appended one at a time, chunk pacing on the wire, footer first with no layout shift, skeleton swap, failure part-way, components per chunk, HEAD, navigating away), plus a shared demo-contract spec that runs in workerd and Netlify Dev.unit:all,integration:all,linear-time:all, all four pkg e2e lanes, the three exec lanes, docs e2e, both adapter suites and the adapter dev lane, shop build and e2e, webhint, docs Lighthouse, and the VS Code suite all pass, along with format, spelling and typecheck.pre-pushskill and the coverage JSON regeneration, which the repo instructions leave to the maintainer.🤖 Generated with Claude Code