You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
⚡ Bolt: defer Stork search loading until requested - #39
I release the following change request under the default LICENSE configuration described here: README.md#license
💡 What
Defer Stork WASM initialization and search-index registration until a visitor opens search. Existing search controls, Ctrl+K, Escape, and Ema hot-reload handling remain intact.
🎯 Why
The generated pages previously initialized Stork and registered its index on every window load, including visits that never use search.
📊 Impact
On visits that do not open search, this avoids downloading the 351,489-byte WASM runtime and 181,263-byte search index: 532,752 bytes (~520 KiB) raw. Local gzip sizing is ~122 KiB combined. It also avoids WASM startup and index parsing. The 23,122-byte Stork JS bundle remains loaded.
🔬 Measurement
Compared the generated output before and after with nix build: all 42 HTML pages now call initialization only from the search-open path; no window-load Stork initializer remains. Asset sizes were measured from the built output.
✅ Verification
nix build --no-link --print-out-paths — passed; generated site reports no broken links.
nix flake check — all checks passed.
Dispatched queue task #10576 (the dispatch supplied no linked issue). A human should confirm first-open search and Ema hot reload in a browser.
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
New Features
Search now loads when opened rather than during every page load, helping pages load without immediately initializing search.
Open search with Ctrl+K or Command+K, and close it with Escape. Opening search focuses the search field.
The Stork search template adds a global controller for opening and closing search, loading or refreshing the index, and handling keyboard shortcuts. A dated note describes how a templates/ overlay can defer initialization until search opens.
Changes: Stork search behavior
Layer / File(s)
Summary
Search controller and index lifecycle templates/components/stork/stork-search-head.tpl, .jules/bolt.md
The template adds Stork assets and a controller for search visibility, index loading and refresh, input focus, and keyboard handling. The note describes the default template’s eager initialization and a templates/ overlay that can defer it.
sequenceDiagram
actor User
participant Controller as window.emanote.stork
participant Stork
participant SearchInput
User->>Controller: Open search
Controller->>Stork: Initialize or refresh index
Controller->>SearchInput: Focus input
Loading
Possibly related PRs
developing-today/zettel#36: Updates sidebar and footer controls that call window.emanote.stork.toggleSearch(), the controller interface defined here.
Merge Risk: Minimal · up to 211ff
No confirmed search failure currently blocks merging. First-open search and hot reload still warrant browser checks.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title clearly and concisely describes the main change: deferring Stork search loading until the visitor requests search.
Description check
The description includes the required default-license declaration and provides clear sections for the change, rationale, impact, measurement, and verification. It also identifies the remaining browser…
Docstring Coverage
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description includes the required default-license declaration and provides clear sections for the change, rationale, impact, measurement, and verification. It also identifies the remaining browser validation for first-open search and Ema hot reload.
Full details: Docstring Coverage
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 0 files. (2 skipped: 2 unsupported.)
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
23-23: Trivial · Maintainability & Code Quality · Low value
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Store the initialized flag on window.emanote.stork. Do not add a second global property.
The code adds the ad-hoc global window.__emanoteStorkInitialized. It does this to preserve state across Ema hot reload, which re-runs the inline script. Line 19 resets window.emanote on every run, so state on window.emanote.stork is lost. Read the previous controller before the reset instead. This keeps all search state in the window.emanote namespace.
Use var, not const. A classic inline script can re-run in the same document, and a repeated top-level const declaration throws a SyntaxError.
The deferred-loading logic is otherwise consistent. loadIndex sets indexInitialized synchronously, so rapid toggles cannot call stork.initialize twice. The init hot-reload path marks the index stale only when the index was initialized. The sidebar caller window.emanote.stork.toggleSearch() now reaches loadIndex correctly.
Based on learnings: "avoid attaching ad-hoc properties to global objects (e.g., window, globalThis)... Flag code that reads or writes global-scope properties."
Also applies to: 60-60
Source: Learnings
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: abed20f4-0c63-4216-9d57-318b35c0f14e
Commits
Reviewing files that changed from the base of the PR and between 4ea6711 and 211ffea.
Files selected for processing: 2
.jules/bolt.md
templates/components/stork/stork-search-head.tpl
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
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
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
Defer Stork WASM initialization and search-index registration until a visitor opens search. Existing search controls, Ctrl+K, Escape, and Ema hot-reload handling remain intact.
🎯 Why
The generated pages previously initialized Stork and registered its index on every window load, including visits that never use search.
📊 Impact
On visits that do not open search, this avoids downloading the 351,489-byte WASM runtime and 181,263-byte search index: 532,752 bytes (~520 KiB) raw. Local gzip sizing is ~122 KiB combined. It also avoids WASM startup and index parsing. The 23,122-byte Stork JS bundle remains loaded.
🔬 Measurement
Compared the generated output before and after with
nix build: all 42 HTML pages now call initialization only from the search-open path; no window-load Stork initializer remains. Asset sizes were measured from the built output.✅ Verification
nix build --no-link --print-out-paths— passed; generated site reports no broken links.nix flake check— all checks passed.Dispatched queue task #10576 (the dispatch supplied no linked issue). A human should confirm first-open search and Ema hot reload in a browser.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit