Skip to content

⚡ Bolt: defer Stork search loading until requested - #39

Open
dezren39 wants to merge 1 commit into
mainfrom
bolt/defer-stork-search
Open

dezren39 wants to merge 1 commit into
mainfrom
bolt/defer-stork-search

Conversation

@dezren39

@dezren39 dezren39 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member
  • 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.


Autofix with [code]smith
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.
    • Search can refresh an outdated index when needed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T14:58:03.687962Z 211ffea PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Sequence Diagram(s)

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: Passed 5

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: deferring Stork search loading until the visitor requests search.
Description check Passed 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 Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1

templates/components/stork/stork-search-head.tpl: 1

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.

♻️ Proposed change

-      window.emanote = {};
+      var previousEmanoteStork = window.emanote && window.emanote.stork;
+      window.emanote = window.emanote || {};
       window.emanote.stork = {
         searchShown: false,
         indexIsStale: false,
-        indexInitialized: !!window.__emanoteStorkInitialized,
+        indexInitialized: !!(previousEmanoteStork && previousEmanoteStork.indexInitialized),
             this.indexInitialized = true;
-            window.__emanoteStorkInitialized = true;

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 branch was successfully deployed

1 active deployment
ci — 211ffea8 Deployed Nov 5, 2026 by dezren39 via ci #371
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

Successfully merging this pull request may close these issues.

1 participant