​​Core Web Vitals​Chrome,HTML,JavaScript,Lighthouse,Playwright,web-vitals

Thumbnail of post image 056

ぼかした低画質の画像を先に出し、本当の画像に差し替える読み込み方で、Core Web Vitals の LCP がどう変わるかを測りました。仮の画像の縦横が本当の画像と同じだと、LCP は仮の画像が出た時刻になり、本当の画像が出た時刻 ...

​​Node.js​ES Modules,JavaScript,npm,トラブルシュート

Thumbnail of post image 160

Node.js で import を書くと出る「Cannot use import statement outside a module」を、npm init -y の type: commonjs で起こし、type を modul ...

​​Core Web Vitals​CSS,iframe,Lighthouse,Playwright,web-vitals

Thumbnail of post image 040

YouTube の動画などを iframe で埋め込むとき、CSS の aspect-ratio で最初から高さを決めると CLS は 0 でした。読み込み後にスクリプトで高さを直すと 0.048、高さを後から知らせる投稿の埋め込みで ...

​​React​TypeScript,useEffect,useState,Vite,トラブルシュート

Thumbnail of post image 165

子コンポーネントから親の state を変えると出る「Cannot update a component」の警告は、子のレンダー中に親の set 関数を呼んでいるのが原因です。親で計算するか、onClick に関数を渡す形に直すと消え ...

​​Core Web Vitals​Chrome,CSS,HTML,Lighthouse,web-vitals

Thumbnail of post image 145

ヒーロー部分の大きな画像を CSS の background-image で表示していて、Core Web Vitals の LCP が遅いときは、HTML の head に link rel=”preload” ...

​​React​TypeScript,useState,Vite,トラブルシュート

Thumbnail of post image 111

Reactで、ログインした瞬間などに出る「Rendered more hooks than during the previous render.」というエラーのよくある原因は、早めの return のあとに書いた useState ...

​​Core Web Vitals​Chrome,JavaScript,Long Animation Frames API,Playwright,web-vitals

Thumbnail of post image 099

インクリメンタルサーチで1文字入力するたびに一覧を書き換え、そのつど要素の高さを読み取ると、レイアウトが1,000回ほど起きて INP が 688ms になりました。書き込みを先にまとめてから高さを読み取ると、INP は 80〜104 ...

​​React​TypeScript,useState,Vite,トラブルシュート

Thumbnail of post image 130

React の「Invalid hook call」は、useState などのフックをイベントハンドラーの中や、コンポーネントの外で呼んだときと、自作のコンポーネントライブラリを入れて React が2つになったときに出ます。実際に ...

​​Core Web Vitals​CSS,Lighthouse,Playwright,web-vitals,フォント

Thumbnail of post image 105

Web フォントへの入れ替わりで行の折り返しが変わると、本文がずれて Core Web Vitals の CLS が上がります。代替フォントを size-adjust で Web フォントの幅に合わせると、検証したページでは CLS ...

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 082

API から取ってきたユーザー情報や Date を JSX にそのまま書くと、画面が真っ白になり、コンソールに Objects are not valid as a React child と出ます。中の文字列を書くか、toLocal ...

​​Core Web Vitals​Chrome,JavaScript,TypeScript,web-vitals

Thumbnail of post image 118

開発中にページの表示速度や操作への反応の速さを確かめたいときは、web-vitals の onLCP・onCLS・onINP で Core Web Vitals の値をコンソールに出せます。値はクリックやタブの切り替えの後に出ます。

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 069

map で一覧を描くとコンソールに「Each child in a list should have a unique “key” prop.」と出るのは、map が返す要素に key がないためです。データの ...

​​Core Web Vitals​Chrome,JavaScript,Lighthouse,Playwright,web-vitals

Thumbnail of post image 029

Lighthouse や PageSpeed Insights で LCP が遅いと出たときに、Core Web Vitals の LCP の要素がどれかを調べる方法です。コンソールに貼るスニペット、web-vitals、Lighth ...

​​Git​コマンドライン

Thumbnail of post image 192

git log でコミット履歴を検索する方法です。–grep でメッセージの言葉、– の後ろにファイル、–since と –until で日付を指定して絞り込み、組み合わせて探す方法を、 ...

​​Bun​CLI,TypeScript

Thumbnail of post image 191

Bun の bun build –compile なら、TypeScript の CLI ツールを、Bun も node_modules もいらない1つの実行ファイルにして配布できます。作り方と、Hello world で ...

​​Git​コマンドライン,トラブルシュート

Thumbnail of post image 192

git pull が「Need to specify how to reconcile divergent branches.」で止まったら、–no-rebase(マージ)か –rebase(リベース)を付けて ...

​​Bun​Node.js,TypeScript,パフォーマンス

Thumbnail of post image 183

TypeScript のスクリプトや CLI をビルドせずに直接実行したいとき、Bun と Node.js の型を取り除く機能(–experimental-strip-types)のどちらが速いかを計りました。起動から終了 ...

​​Git​コマンドライン

Thumbnail of post image 195

.env や node_modules、ログファイルを間違えてコミットしたあとで .gitignore に書いても、Git は変更を追い続けます。git rm –cached で追跡から外し、手元のファイルは残したまま、次 ...

​​Bun​Node.js,npm,パッケージ管理

Thumbnail of post image 024

npm から Bun に乗り換えるときや、CI で依存のバージョンを固定したいときに知っておきたい、bun.lock と package-lock.json の違いです。中身の書き方、差分の大きさ、CI での食い違いの扱い、互いのファ ...

​​Git​コマンドライン

Thumbnail of post image 117

間違えて消したファイルや、書き換えてしまったファイルは、git restore で最後のコミットの状態に戻せます。git add の取り消し(–staged)、前のコミットからの取り出し(–source)、一部 ...

​​Bun​SQLite,TypeScript

Thumbnail of post image 153

Bun の bun:sqlite なら、npm のパッケージを入れずに SQLite のファイルを読み書きできます。CLI ツールや小さなアプリにデータベースを持たせたいときの基本の書き方と注意点を、実際の出力と1万行の書き込み時間で ...

​​Git​コマンドライン

Thumbnail of post image 078

git merge で「CONFLICT (content): Merge conflict in」と表示されて止まったときは、ファイルの <<<<<<>>>>>> ...

​​Bun​CLI,Node.js,npm

Thumbnail of post image 137

npm scripts の起動が遅いとき、npm run を bun run に替えるとどれだけ速くなるかを計りました。何もしないスクリプトで npm run は 97.4 ms、bun run は 5.0 ms でした。中で nod ...

​​Git​コマンドライン

Thumbnail of post image 139

作業の途中でブランチを切り替えたいのに、コミットしていない変更が切り替え先とぶつかって git switch が止まるときは、git stash で変更を一時的によけられます。pop・apply で戻す方法と、追跡していないファイルや ...