惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
U
Unit 42
V
Visual Studio Blog
D
DataBreaches.Net
F
Fortinet All Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
博客园 - 叶小钗
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
D
Docker
G
Google Developers Blog
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
S
SegmentFault 最新的问题

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Zero-JS Search: Building a Live-Filter with Turbo 8 Page ...
Zil Norvilis · 2026-06-19 · via DEV Community
Cover image for Zero-JS Search: Building a Live-Filter with Turbo 8 Page Morphing

Zil Norvilis

I’ve lost count of the number of hours I’ve spent in the past building "Live Search" features.

In the old days, you had to write custom AJAX listeners, handle the "white flash" of reloads, and manually manage the browser's history. Later, with Turbo 7, we used Turbo Frames, but that meant wrapping everything in specific tags and losing the "state" of the rest of the page.

In 2026, the game has changed. With Turbo 8 Page Morphing, we can build a live-filtering search bar that feels like a heavy React app, but uses 100% standard Rails controllers and almost zero custom JavaScript.

The secret is that Turbo 8 can "morph" the page - it refreshes the HTML but keeps your scroll position and the focus inside the search input perfectly intact. Here is how to build it in 3 steps.

STEP 1: Enable Morphing

First, we need to tell our application that we want to use the new Morphing behavior instead of the old "Replace" behavior.

Open your main application layout and add these two tags to the <head>.

<!-- app/views/layouts/application.html.erb -->
<head>
  <!-- ... -->
  <%= turbo_refreshes_with method: :morph, scroll: :preserve %>
  <%= yield :head %>
</head>

STEP 2: The Search Form and Controller

We are going to use a standard HTML form. No remote: true, no complex setups. Just a simple GET request.

# app/controllers/products_controller.rb
class ProductsController < ApplicationController
  def index
    @products = Product.all

    if params[:query].present?
      @products = @products.where("name ILIKE ?", "%#{params[:query]}%")
    end
  end
end

In your view, create the search bar. The "trick" here is that we want the form to submit as the user types. Since HTML doesn't do this natively, we use a tiny 2-line Stimulus controller that I keep in every project as a "utility" tool.

<!-- app/views/products/index.html.erb -->
<div class="p-8">
  <div data-controller="autosave">
    <%= form_with url: products_path, method: :get, 
                  data: { autosave_target: "form", turbo_frame: "_top" } do |f| %>

      <%= f.text_field :query, 
            placeholder: "Search products...", 
            value: params[:query],
            data: { action: "input->autosave#save" },
            class: "border-2 border-black p-2 w-full" %>
    <% end %>
  </div>

  <div id="products_list" class="mt-8 grid grid-cols-3 gap-4">
    <%= render @products %>
  </div>
</div>

STEP 3: The Utility Controller (The only JS you need)

This is the only JavaScript we need. It is a reusable "autosave" controller that simply submits the form whenever you type.

// app/javascript/controllers/autosave_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["form"]

  save() {
    // This triggers the standard Rails form submission
    this.formTarget.requestSubmit()
  }
}

How it works (The Magic)

In the old days, calling requestSubmit() as you typed would be a disaster. The page would reload, you would lose focus on the text box, and the cursor would jump to the beginning of the line.

With Turbo 8 Morphing:

  1. You type the letter "A".
  2. Stimulus tells the form to submit.
  3. Rails returns the entire index page with only the "A" products.
  4. Turbo 8 compares the new HTML to the current page.
  5. It sees that the text input is the same, so it leaves it alone (preserving your cursor and focus).
  6. It sees the product list has changed, so it morphs those elements seamlessly.

The user perceives a lightning-fast, reactive live filter, but you are just writing standard, boring Rails code.

Summary

As a solo developer, your goal is to stay out of "JavaScript Land" as much as possible. By leveraging Turbo 8 Page Morphing:

  1. No JSON APIs: You don't need to build a search endpoint.
  2. No Manual DOM Updates: You don't have to write code to append or remove items.
  3. No Focus Issues: Browsers handle the state of the input automatically.

This is the "One-Person Framework" at its best: high-end features with zero-maintenance code.