Repository navigation
Description
Needs your OK: this adds a small script organizers can paste with the embed code, so the frame fits the sheet. Swap pipeline:proposed for pipeline:ready to have it built.
Part of #1061.
What happens
After #1062 and #1064, an embedded signup is a fixed 600 px tall. A short signup leaves a gap under it. A long one scrolls inside the frame, a scrollbar inside a page that already scrolls. The host page can't measure the frame's content itself, because it's another origin.
Fix, in outline
- The embed sizes to its content. The layout (
src/app/s/[slug]/layout.tsx), the page andstate-message.tsxall usemin-h-[100svh]. Inside a frame that's the frame's own height, so a page measured that way never reports less than the frame and the frame never shrinks. Drop it in the embed, the same way A signup can't be shown inside another website's page #1062 makes these files drop the footer and open links in a new tab there. Nothing in the embed may be sized by the frame's height (vh,svh,h-fullon the root), or each new height grows the content and the frame grows without end. - The embed reports its height. A small client component, only when framed (
window.parent !== window), watches the embed's outermost wrapper with aResizeObserverand posts the height message (below) towindow.parenton load and whenever it changes. It measures the wrapper, notdocument.documentElement.scrollHeight, which is never less than the frame's own height. The height isn't private, so the target origin is'*'. - Only the embed loads it. Render the reporter from the embed's own files (its page, and its
not-found.tsxif A signup can't be shown inside another website's page #1062 gave it one), not from the sharedlayout.tsx: a client component that a server layout imports ships with every page under it,/s/[slug]included. - The sign-up dialog has room, and gets on screen.
BottomSheetis fixed-position and outside the page's flow, capped atmax-h-[85vh], so it adds nothing to the height, and in a frame85vhis 85% of the frame. In a frame as tall as a long signup, the dialog sits at the bottom (phone) or middle (desktop) of the whole frame, which may be off the visitor's screen, and it never gets short enough to scroll inside itself. In a frame as short as a one-slot signup, it's squeezed. So, in the embed:- while the dialog is open, the reported height is never less than the starting height (
EMBED_DEFAULT_HEIGHT, below), and it goes back to the content's height when the dialog closes; - the dialog's maximum height is 85% of the starting height rather than of the frame, through a new optional prop on
BottomSheetthatcommit-dialog.tsxpasses only in the embed, so no other page changes. With both, the dialog behaves as it does in A signup can't be shown inside another website's page #1062's fixed 600 px frame; - while it's open, the embed posts the dialog's position (below), and
embed.jsscrolls the host page to it.
- while the dialog is open, the reported height is never less than the starting height (
- A tiny script,
/embed.js(where it comes from is below). It listens for the messages below, and sets the iframe's height and the window's scroll position, nothing else. - The share panel has no code for putting a signup on a website #1064's code gains one line,
<script async src="https://…/embed.js"></script>, after the<iframe>. The code builder works out the script's address from the embed address it already takes (new URL('/embed.js', embedUrl)), so the share panel needs nothing new. The iframe keeps its starting height, so a site that strips scripts still gets a usable frame. - One starting height. The share panel has no code for putting a signup on a website #1064 gives the
<iframe>height="600". Use that number from where The share panel has no code for putting a signup on a website #1064's code builder keeps it, as an exported constant (sayEMBED_DEFAULT_HEIGHT). If The share panel has no code for putting a signup on a website #1064 wrote600inline, move it into such a constant beside the builder, and use it in the builder, the reporter and the dialog's cap.
The messages
Every page that carries the code depends on these, so they're fixed here. A small module both sides import, src/lib/embed-messages.ts, holds the type names, the messages' TypeScript types, and the functions that build them.
| Message | When the frame posts it |
|---|---|
{ type: 'opensignup:height', height: number } |
On load, and whenever the content's height changes. height is the embed's height in CSS pixels, a whole number rounded up, never less than the starting height while the dialog is open. |
{ type: 'opensignup:dialog', top: number, height: number } |
While the sign-up dialog is open: when it opens, and whenever it or the frame changes size. top is the dialog's top edge, measured from the top of the frame, and height is its height, both in whole CSS pixels. Nothing is posted when it closes. |
- No version field. The type names are namespaced (
opensignup:), so new behaviour gets a new type, and a new field can be added to a message without breaking old copies of the script, which ignore fields they don't know. A field never changes meaning and is never removed; a change that can't keep to that is a new type. - One way only. The frame posts to
window.parent. The host never posts to the frame. - How
embed.jschecks a message:- It reads its own origin once, while it runs:
new URL(document.currentScript.src).origin. A classic script hascurrentScriptwhile it runs,asyncincluded. If it's null (the script was loaded some other way), the script does nothing, and the frame keeps its starting height. - It drops any message whose
event.originisn't exactly that origin. - It drops any message whose
event.sourceisn't thecontentWindowof an<iframe>on the page. It looks the iframes up when the message arrives, so frames added after the script loaded still work. The iframe it finds is the one it changes. - It drops any message whose
dataisn't an object with a knowntype, or whose numbers aren't finite (heightabove 0,top0 or more). Unknown types and extra fields are ignored, never an error.
- It reads its own origin once, while it runs:
- What
embed.jsdoes with them:opensignup:height: sets that iframe'sstyle.heightto the height in pixels.opensignup:dialog: scrolls the window the least distance that shows the whole dialog, working out where it is from the iframe'sgetBoundingClientRect().topplustop. A dialog taller than the window gets its top edge at the top. If the dialog is already in view, it doesn't scroll.- It sets no globals and loads nothing. Two copies on one page (two embeds, each with its line) both handle each message, which is harmless: they set the same height, and the second finds the dialog already in view.
Where embed.js comes from
public/ holds only images, and a file there isn't type-checked (allowJs is off) or unit-tested from TypeScript. So:
- The script's code is a TypeScript function,
installEmbedHostinsrc/lib/embed-host-script.ts, that uses nothing outside its own body: no imports, no module constants. The message type names come in as an argument. - A route handler,
src/app/embed.js/route.ts, serves(<the function's source>)(<the type names as JSON>);, built once at module load frominstallEmbedHost.toString(). A dotted folder already serves a file-like address (src/app/api/signups/[id]/export.csv/route.ts). - Its headers:
Content-Type: text/javascript; charset=utf-8andCache-Control: public, max-age=86400. Like the protected-resource metadata route, it'sforce-dynamic, so its ownCache-Controlreaches the browser. - It's served whether or not
EMBEDS_ENABLEDis on. With embeds off there's no frame for it to hear from, and a site that still carries the line gets no error.
So the script is linted, type-checked and unit-tested like any other module, with no build step, no new dependency and nothing in public/.
Watch for
- This script runs on other people's websites. Keep it tiny and dependency-free, have it change nothing but the iframe's height and the window's scroll position, and keep the messages above working: sites will hold old copies of the code for years.
toString()serves exactly what the build compiled. A function that reaches outside its own body passes a unit test that imports it, and breaks on host pages. So the unit tests run the served text, not the imported function, and the e2e spec runs the production build's.- Budgets. The reporter adds a little JavaScript to
/s/[slug]/embed'sfirstLoadJsKb(A signup can't be shown inside another website's page #1062 adds the entry)./s/[slug]'s mustn't change. - The help article from The help pages don't say how to put a signup on a website #1066 ("Put a signup on your website") describes the code. It needs the script line, and what happens on a site that strips scripts. Re-take the help screenshots that show the code (
pnpm help:screenshots), the share panel's increate-and-publish-a-signupincluded. Help is English only. - Text. This change adds no text people read. If it does add some (say, to the share panel's line about the code), it goes in
en.jsonwith every shipped language (Swedish today) through thetranslateskill in the same PR, andsrc/messages/en.d.json.tsis committed after a build. - German. Open PR Translate OpenSignup into German, not switched on yet #1060 adds a German catalog without shipping it. If it lands first, German is a test language: the e2e seed makes German signups and the no-English checks run on them, so any new text needs German too.
- An embedded signup forgets who signed up in that browser #1065 also changes the embed page (a cookie for returning participants). Whichever lands second has a small merge.
- CHANGELOG: an entry for the script and the line it adds to the code.
Choices this makes
- A script on other people's websites, for good. Approving this commits every instance to serving
/embed.jsto organizers' websites, and to keeping the two messages above working for embeds already placed. New fields and new types can be added; existing ones can't change meaning or go away. - Worth doing now? The fixed height works. Default: build it after The help pages don't say how to put a signup on a website #1066, so it's ready when organizers ask, but it's fine to wait until they do.
- The script lives at
/embed.json each instance, served from TypeScript by a route handler rather than written by hand inpublic/or made by a build step. It's the least machinery that keeps the script linted, type-checked and tested. - Cached for a day. Pasted code can't carry a version, so the address never changes, and a fix reaches visitors once their copy expires. A day keeps that short and costs little for a script this size.
- No version field in the messages. The namespaced types and "add, never change" keep old copies working.
- An open dialog is brought on screen by scrolling the host page, rather than shrinking the frame while it's open.
- The dialog behaves as in a 600 px frame. The frame is at least the starting height while it's open, and the dialog is capped at 85% of that, so it scrolls inside itself as A signup can't be shown inside another website's page #1062 checks, rather than spreading down a very tall frame or squeezing into a short one.
Order
After #1064, because it changes the code the share panel gives out, and after #1066, because it edits #1066's help article.
Done when
- A Playwright spec with a host page on another origin (as A signup can't be shown inside another website's page #1062's specs use) that carries the code sees the iframe's height match the sheet, for a short signup and a long one.
- On a long signup, tapping a row near the top shows the whole sign-up dialog on screen, at desktop and phone width. On a short one, the frame is at least the starting height while the dialog is open, and fits the sheet again once it closes.
- Without the script line, the frame keeps its starting height.
GET /embed.jsfrom the production server answers withtext/javascript; charset=utf-8andCache-Control: public, max-age=86400.- Unit tests run the exact text
/embed.jsserves, in a jsdom page with nothing else on it, and show that:- a height message from the right origin and frame sets that frame's height;
- one from another origin, from a window that isn't one of the page's iframes, with an unknown type, or with a bad number changes nothing;
- a dialog message scrolls the least distance, and not at all when the dialog is already in view.
- A unit test pins each message the frame posts, field for field.
- The code builder's test covers the script line, and The help pages don't say how to put a signup on a website #1066's article and the help screenshots that show the code have it.
/s/[slug]'s first-load JavaScript is unchanged.pnpm lint && pnpm format:check && pnpm typecheck && pnpm knip && pnpm test,pnpm budgetsafterpnpm build, and the e2e suite pass.
From the owner's notes, checked against main at 0a71fbf, and reviewed by a second agent against the code. https://claude.ai/code/session_016YZ9SSL4C6UVyX63KaR1bL
Revised against main at d8787e9: pinned both messages and how embed.js checks them, said where its source lives and how it's served, shared the starting height, settled the dialog's size in the frame, and added the order after #1066. https://claude.ai/code/session_016YZ9SVTB9qLweVn9KzZpdf
Activity
richshaw commentedon Nov 18, 2026
Revised the brief against
mainat d8787e9 so it can be approved as written:opensignup:heightandopensignup:dialog), with howembed.jschecksevent.originandevent.source, what it does with unknown types and bad numbers (ignores them), and no version field: new fields and types can be added, existing ones never change.embed.jscomes from. A file inpublic/isn't type-checked or unit-tested. The script is now a TypeScript function insrc/lib/embed-host-script.ts, served from its own source by a route handler at/embed.jsand cached for a day. That needs no build step and no new dependency, and the unit tests run the exact text it serves.height="600"becomes a shared constant. An embedded signup has a fixed height, so it shows a scrollbar or a gap #1067 uses it, and adds it if The share panel has no code for putting a signup on a website #1064 didn't, in the code builder, the embed's reporter and the dialog's cap.max-h-[85vh]is usable" to the builder. In a very tall frame the dialog never scrolls inside itself, and in a short one it's squeezed. The default now is that the frame is at least 600 px while the dialog is open and the dialog is capped at 85% of that, so it behaves exactly as in A signup can't be shown inside another website's page #1062's fixed frame. Edit "Choices this makes" if you'd rather have something else./s/[slug]'s budget unchanged is now a requirement.https://claude.ai/code/session_016YZ9SVTB9qLweVn9KzZpdf
Generated by Claude Code