Skip to content

fix(socratiq): enable AI companion and free Ctrl+/ from search - #1978

Open
farhan523 wants to merge 1 commit into
harvard-edge:devfrom
farhan523:fix/enable-socratiq-and-shortcut
Open

fix(socratiq): enable AI companion and free Ctrl+/ from search#1978
farhan523 wants to merge 1 commit into
harvard-edge:devfrom
farhan523:fix/enable-socratiq-and-shortcut

Conversation

@farhan523

Copy link
Copy Markdown
Contributor

Problem

On the SocratiQ page the docs tell readers to press Ctrl + / to open the AI chat. In practice:

  1. The SocratiQ bundle is disabled in the HTML configs, so nothing loads.
  2. Even with it enabled, Ctrl + / opens Quarto's search box, not the chat.
  3. When it does load, the chat sidebar flashes open-then-closed on every page load.

Root causes (traced in code)

  • Disabled bundle: the <script … bundle.js> tag is commented out in config/_quarto-html-vol1.yml / -vol2.yml ("disabled pending quiz regeneration").
  • Shortcut collision: Quarto's search (quarto-search.js) binds the / key on keyup and checks only event.key === "/", ignoring modifiers — so Ctrl + / matches and opens search. SocratiQ's own handler runs on keydown and calls preventDefault(), which cannot stop Quarto's separate keyup listener.
  • Load flash: the slide-out panel ships with transition-transform in its initial markup. On first paint (before the shadow-root styles apply), the panel renders on-screen, then animates off as styles load — a visible flash.

Changes

  • Enable SocratiQ in the vol1/vol2 HTML configs and add tools/scripts/socratiQ/*.js as a project resource so the bundle is served.
  • socratiq-search-shortcut-fix.js (new): a capture-phase keyup listener that stopImmediatePropagation()s / only when Ctrl/Cmd is held, freeing Ctrl + / for SocratiQ while leaving plain / search untouched.
  • Flash fix: remove transition-transform from the panel's initial template in socratiq/src_shadow/index.html + indexHtml.js (and the built bundle.js to match). The open/close handlers re-add the class, so animations still work — only the first-paint flash is gone.

Before → After (for readers)

Before After
SocratiQ chat Disabled Loads & works
Ctrl + / Opens search Opens chat
Plain / Search Search (unchanged)
Page load Sidebar flashes No flash

⚠️ Maintainer note — please read before merging

This PR re-enables a bundle that was intentionally turned off "pending quiz regeneration." If the quiz pipeline isn't ready, you may want to merge only the shortcut + flash fixes and keep the enable out — happy to split the PR that way. The shortcut and flash fixes are correct and low-risk regardless of when the bundle is enabled.

The bundle.js change is a build artifact; the same fix is applied to its source in socratiq/src_shadow/, so a rebuild reproduces it.

Testing

Verified locally with quarto preview: Ctrl + / opens the chat panel (no search box), plain / still opens search, no load flash, and chat streams responses end-to-end via the Cloudflare workers (tested through a local CORS proxy since the workers allowlist mlsysbook.ai).

The SocratiQ AI learning companion was fully disabled and, even when
enabled, its documented Ctrl+/ shortcut opened Quarto's search box
instead of the chat. This restores a working end-to-end experience.

Changes:
- Re-enable the SocratiQ bundle in the vol1/vol2 HTML configs and add
  tools/scripts/socratiQ/*.js as a project resource so it is served.
- Add socratiq-search-shortcut-fix.js: Quarto's search binds the "/"
  key on keyup and ignores modifiers, so Ctrl/Cmd+/ also matched and
  opened search. SocratiQ's handler runs on keydown; preventDefault
  there cannot stop Quarto's separate keyup listener. The shim
  stopImmediatePropagation()s "/" keyup only when Ctrl/Cmd is held,
  freeing Ctrl+/ for SocratiQ while leaving plain "/" search intact.
- Fix the chat panel flashing open-then-closed on page load: the
  slide-out menu shipped with `transition-transform` in its initial
  markup, so the pre-style first paint animated as styles applied.
  Remove it from the initial template (src_shadow + built bundle);
  the open/close handlers re-add it, so animations still work.

Note: the bundle was disabled "pending quiz regeneration"; this PR
re-enables it. Maintainers should confirm the quiz pipeline is ready
before merging the enable portion.
@github-actions github-actions Bot added area: book Textbook content (Vol I & II) type: bug bug in rendering labels Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: book Textbook content (Vol I & II) type: bug bug in rendering

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant