I Built a Bilingual Hanukkah Menorah in 2D and 3D — and One Candle Refused to Sync

2026-12-03来源 dev.toEnglish

Every December I think about making something for Hanukkah. This year I finally did it: a web app that shows the menorah, tells you the exact candle-lighting time for your city, lets you light the candles in the correct ceremonial order, and even simulates them burning down in real time. I built it in pure HTML, CSS and JavaScript, and I did the whole thing on a tablet. It was the most educational project I've made so far, mostly because of the bugs that refused to die. Here's the story.

What the app does

The app has two views of the same menorah. The first is a 2D SVG candelabrum with nine candles: eight for the nights plus the Shamash, the helper candle in the center. You tap a candle to light it, and the app enforces the real halakhic order — Shamash first, then the newest candle, working left to right. If you tap the wrong one, the correct candle glows gold and a message tells you to light it first. Each lit candle flickers, throws tiny sparks, drips wax, and slowly shrinks over four hours, which is how long a real Hanukkah candle burns. There's a demo mode that compresses those four hours into three minutes so you can practice the ritual without waiting.

The second view is a 3D Three.js menorah with the same nine candles, PBR textures for the wax, an HDR environment for the reflections on the gold, and orbit controls so you can spin it with your finger. Both views are fully bilingual — Spanish and English — and they share the same state, so a candle you light in 2D is lit in 3D and vice versa.

Real lighting times for real cities

The hardest "feature" wasn't the graphics, it was the clock. Hanukkah candles are lit at nightfall, which depends on where you are and what day of the week it is. On Friday the candles go up before sunset to respect Shabbat, and on Saturday after Shabbat ends. So I implemented the NOAA sunset algorithm in plain JavaScript, fed it the latitude, longitude and timezone of the selected city, and added the weekday offsets. The result is that a user in Caracas and a user in Jerusalem get different, correct times for the very same night. I also built a date table that covers Hanukkah from 2024 to 2124, so the countdown doesn't stop after this year — when one festival ends, the app quietly starts counting down to the next one.

The bugs that taught me the most

I want to be honest about the bugs, because they taught me more than any tutorial.

First, the 3D scene loaded but the camera controls crashed with "Cannot access 'controls' before initialization". The cause was the temporal dead zone: I was calling a function that read a const variable before that variable had been declared. The fix was to declare it with let, initialize it to null, and guard every use with if (controls). Lesson: with const, order matters more than you think.

Second, my OrbitControls and RGBELoader files threw "Cannot use import statement outside a module". I had downloaded the ES-module versions but was loading them with plain tags. Lesson: know which build of a library you&#39;re grabbing.</p> <p>Third, and most painful, the 2D and 3D candelabros wouldn&#39;t sync. The event &#39;storage&#39; only fires between different tabs, not when you navigate from index.html to 3d.html in the same tab. So I added a &#39;focus&#39; listener that re-reads localStorage every time the page regains attention. Lesson: browser events have hidden scopes.</p> <p>Fourth, the central Shamash candle. The 2D view started with everything off, but the 3D view kept forcing the Shamash lit on load, and the demo mode didn&#39;t light it either. The bug was a hardcoded litCandles.add(4) in three different places. Removing it made both views start clean and respect whatever the user had saved. Lesson: a default state is still a decision, and it has to be the same decision in every file.</p> <p>Finally, the cache. On my tablet, Ctrl+F5 simply doesn&#39;t refresh JavaScript. The fix was cache busting: appending ?v=3 to every script and stylesheet link. Lesson: in production, version your assets or you&#39;ll debug ghosts.</p> <h2> <a name="building-on-a-tablet" href="#building-on-a-tablet" class="anchor"> </a> Building on a tablet </h2> <p>A small note on how this was made. I do all of my development on a tablet, not a desktop. That constraint shaped the project: I avoided build tools, frameworks and package managers, and stuck to files I could edit, upload and test directly. No bundler, no npm, just vanilla HTML, CSS and JavaScript plus the Three.js build. It&#39;s slower in some ways and clearer in others, because every line is something I had to understand, not just install. If you&#39;re a beginner or you work on limited hardware, please know that &quot;no computer&quot; is not &quot;no project&quot;. The web is open and it runs on the device in your hands.</p> <h2> <a name="closing" href="#closing" class="anchor"> </a> Closing </h2> <p>The whole thing is live on GitHub Pages, free, with no backend and no tracking. It&#39;s a small tool for a real holiday, and it&#39;s also my way of keeping my hands busy with code I actually care about. If you celebrate Hanukkah, I hope the lighting times and the ceremonial order make your evenings a little easier. If you don&#39;t, I hope the bug stories make you smile, because every single one of them was a moment where I wanted to throw the tablet out the window and didn&#39;t.</p>

原文:https://www.a8q9.cn/en/article/i-built-a-bilingual-hanukkah-menorah-in-2d-and-3d-and-one-candle-refused-to-sync-187a9c.html

相关文章