Weekly Retrospective: The Last Week of July

The magic of height: 0

When the height is responsive and you want an area between fixed elements to flex into the remaining space, the magic combination of height: 0 + flex-grow lets it take up exactly the space that’s left.

Focus in/out animation

When the input gains focus, the title area disappears and the content moves up. When it loses focus (blur), the title returns and the content moves down. During this process, clicking a button or another element outside the input triggers only focus out, without the click event. Solution → I used outside click detection to treat the area containing the button as part of the focused area. —> This isn’t a fundamental solution. Areas outside that outside-click boundary still can’t be clicked while the input is focused. —> Looking into the cause, I found event bubbling. An event propagates from the element where it occurs up to the topmost element. For example, clicking a button starts a click event at the button, which then propagates to its ancestors.

The blur event: blur fires when an element loses focus. At that moment, blur occurs, followed by click. But because blur runs synchronously, its handler executes before the click handler.

What happens: The input loses focus, triggering blur and its handler. Only after the blur handler executes does the button’s click event occur. If the blur handler prevents event processing for some reason or changes the DOM, the later click event may not be handled correctly. Solutions: Adjust the event order: when running an animation on blur, perform the event handling asynchronously. This can let the click event be handled first.

const handleBlur = (event) => { setTimeout(() => { // Code to run the animation on blur }, 0); }; Add a condition to the handler: add a condition in the blur handler to check whether a button was clicked. javascript Copy code const handleBlur = (event) => { if (document.activeElement.tagName === ‘BUTTON’) { // Handle a button click return; } // Code to run the animation on blur };

Rerendering the funnel component

The cause of the rerenders was in the funnel, rather than the internals I’d been investigating. The value changed whenever the funnel’s props changed.

Logical OR (||)

  • Returns the right operand when the left operand is falsy (for example, false, 0, "", null, undefined, or NaN).

  • Example:

    javascriptCopy code
    const result = value || 'default';
    

Nullish coalescing (??)

  • Returns the right operand only when the left operand is null or undefined.

  • Example:

    javascriptCopy code
    const result = value ?? 'default';
    

Summary of the difference

  • || handles all falsy values.
  • ?? handles only null and undefined.

https://medium.com/@technicadil_001/how-to-write-better-typescript-codes-dbfe43d85103

https://joshua1988.github.io/ts/usage/mapped-type.html#맵드-타입-실용-예제-2

https://www.albertgao.xyz/2017/10/31/why-this-react-code-not-work-in-production/

Untitled

The problem is caused by component names changing during minification.

Minifiers such as UglifyJS and Terser shorten variable and function names to reduce code size and optimize performance. Long names become one or two characters. This reduces the overall code size and improves loading speed, but can cause problems when logic depends on names. To prevent this, explicitly set a component’s name using displayName so it won’t change during minification.

https://velog.io/@th_velog/웹뷰-Fixed-가상-키보드-VisualViewport-사용

Safari height issues from A to Z

useEffect(() => {
	// Set the --vh variable based on the viewport height
	const setElementHeight = () => {
		const vh = window.innerHeight * 0.01;
		document.documentElement.style.setProperty("--vh", `${vh}px`);
		window.addEventListener("resize", setElementHeight);
	};
	setElementHeight();

	return () => {
		window.removeEventListener("resize", setElementHeight);
	};
}, [selectedBookList])`'calc(var(--vh, 1vh) * 100 - 450px)'};`;

One last word to myself: Don’t solve problems by taping over them and avoiding the issue. Find the cause and solve it.