Replace define:vars with data attributes in redirect scripts#164
Merged
Replace define:vars with data attributes in redirect scripts#164
Conversation
The experimental Rust compiler breaks `is:inline` + `define:vars`
combination, causing redirect variables (pattern, basePath, etc.) to
not be injected into the generated HTML. This made all /patterns/{name}/
redirect pages non-functional.
Switch to data-* attributes with document.currentScript.dataset, which
is the Astro-recommended approach for passing frontmatter variables to
client-side scripts.
https://claude.ai/code/session_01YPWgEDkv5LeTU2XpMTuTxi
Deploying apg-patterns-examples with
|
| Latest commit: |
acb7541
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://361d11b0.apg-patterns-examples.pages.dev |
| Branch Preview URL: | https://claude-fix-alert-redirect-6y.apg-patterns-examples.pages.dev |
Replace define:vars in PracticeDownload, AiGuideActions, and TreeView DemoSection with data-* attributes, following the Astro recommended pattern for passing frontmatter variables to scripts. This eliminates all define:vars usage, which implicitly forces is:inline and is incompatible with the experimental Rust compiler. https://claude.ai/code/session_01YPWgEDkv5LeTU2XpMTuTxi
Without define:vars, the scripts lost their implicit is:inline flag, causing them to be processed as module scripts where TypeScript type checking surfaced pre-existing type issues. Restore is:inline explicitly since these scripts use DOM APIs (querySelectorAll, currentScript) that require inline execution context. https://claude.ai/code/session_01YPWgEDkv5LeTU2XpMTuTxi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
概要
Astroの
define:varsディレクティブをデータ属性に置き換えることで、インライン スクリプトの変数バインディング方式を改善しました。これにより、スクリプトの実行コンテキストがより明確になり、保守性が向上します。変更内容
具体的な変更
src/pages/patterns/[pattern]/index.astro(日本語版)とsrc/pages/patterns/[pattern]/index.astro(英語版)のインラインスクリプトを更新define:vars={{ pattern, defaultFramework, validFrameworks, basePath }}をデータ属性に置き換えdata-pattern={pattern}data-default-framework={defaultFramework}data-valid-frameworks={JSON.stringify(validFrameworks)}data-base-path={basePath}document.currentScriptを使用してデータ属性から値を取得JSON.parse()で復元APGパターン準拠チェック
テスト
リダイレクト機能の動作確認:
破壊的変更
その他
この変更は機能的には同等ですが、
define:varsよりもデータ属性を使用することで、スクリプトの依存関係がより明示的になり、デバッグやメンテナンスが容易になります。https://claude.ai/code/session_01YPWgEDkv5LeTU2XpMTuTxi