Repository navigation
fix: 클라이언트 사이드 이동 후 코드 블록 복사 버튼 동작 - #229
hyoseong1994 wants to merge 2 commits into
Conversation
Expressive Code injects its copy-button and scrollable-block scripts as inline `<script type="module">` next to each code block. MDX compiles them into React elements, which browsers never execute, so a client-side navigation into the first page that has a code block left the copy button dead. Expose the same scripts as a virtual module, import it once from the root route, and drop the inline scripts from the compiled MDX so nothing is bound twice. Closes #222
|
@hyoseong1994 님, 내일까지 코드리뷰하겠습니다! |
RiaOh
left a comment
There was a problem hiding this comment.
Cloudflare Preview URL을 확인하고 싶은데, 어디서 확인할 수 있나요~?
| // 코드 블록 옆 인라인 script 는 클라이언트 사이드 이동에서 실행되지 않으므로, | ||
| // Expressive Code 스크립트는 첫 페이지의 코드 블록 유무와 무관하게 여기서 한 번 실행합니다. | ||
| useEffect(() => { | ||
| void import("virtual:expressive-code-scripts"); |
There was a problem hiding this comment.
void는 에러를 처리해주지 않아, 만약 import("virtual:expressive-code-scripts")가 반환한 Promise가 reject되어도 아무런 처리를 해주지 않습니다.
.catch(console.error)를 추가하여 로그를 남기는 것도 좋을 것 같은데, 어떻게 생각하시나요?
There was a problem hiding this comment.
There was a problem hiding this comment.
@hyoseong1994 오잉, 저는 왜 우측하단에 Deployments가 안보이는걸까요?ㅠ
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
yolophg
left a comment
There was a problem hiding this comment.
확인했는데 별다른 이슈 없어 보여서 승인합니다! Codex 리뷰어도 따봉이군요!👍 수정해주셔서 감사합니다!

Expressive Code는 복사 스크립트를 코드 블록 옆 인라인
<script type="module">로 넣습니다. MDX는 이걸 React 엘리먼트로 컴파일하고 브라우저는 그런 script를 실행하지 않으므로, 코드 블록 없는 문서로 먼저 들어온 뒤 내부 이동하면 복사 기능이 초기화되지 않았습니다.src/mdx/expressive-code.ts— 같은 스크립트를virtual:expressive-code-scripts가상 모듈로 내보내는 Vite 플러그인, 그리고 컴파일된 MDX에서 인라인 script를 걷어내는 rehype 플러그인src/root.tsx— 가상 모듈을 진입점에서 한 번 import. 스크립트 안의MutationObserver가 이후 클라이언트 사이드로 추가되는 코드 블록까지 처리합니다테스팅
lint,tsc -b,format,coverage,build통과체크 리스트