-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow conditional rendering when
RenderScript
is enabled (#1057)
* test: add test cases * fix: allow processing scripts in expressions when `RenderScript` is enabled * test: add test case without src attribute * fix: add `nil` parent guard * test: add new snapshots * chore: changeset * test: remove duplicate snapshot * apply sarah's changeset suggestion Co-authored-by: Sarah Rainsberger <[email protected]> --------- Co-authored-by: Sarah Rainsberger <[email protected]>
- Loading branch information
1 parent
71fb3ef
commit 8cae811
Showing
8 changed files
with
208 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@astrojs/compiler": patch | ||
--- | ||
|
||
Fixes an issue with the conditional rendering of scripts. | ||
|
||
**This change updates a v5.0 breaking change when `experimental.directRenderScript` became the default script handling behavior.** If you have already successfully upgraded to Astro v5, you may need to review your script tags again and make sure they still behave as desired after this release. [See the v5 Upgrade Guide for more details.](https://docs.astro.build/en/guides/upgrade-to/v5/#script-tags-are-rendered-directly-as-declared) |
41 changes: 41 additions & 0 deletions
41
internal/printer/__printer_js__/script_external_in_expression__renderScript__false_.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
[TestPrinter/script_external_in_expression_(renderScript:_false) - 1] | ||
## Input | ||
|
||
``` | ||
<main>{<script src="./hello.js"></script>} | ||
``` | ||
|
||
## Output | ||
|
||
```js | ||
import { | ||
Fragment, | ||
render as $$render, | ||
createAstro as $$createAstro, | ||
createComponent as $$createComponent, | ||
renderComponent as $$renderComponent, | ||
renderHead as $$renderHead, | ||
maybeRenderHead as $$maybeRenderHead, | ||
unescapeHTML as $$unescapeHTML, | ||
renderSlot as $$renderSlot, | ||
mergeSlots as $$mergeSlots, | ||
addAttribute as $$addAttribute, | ||
spreadAttributes as $$spreadAttributes, | ||
defineStyleVars as $$defineStyleVars, | ||
defineScriptVars as $$defineScriptVars, | ||
renderTransition as $$renderTransition, | ||
createTransitionScope as $$createTransitionScope, | ||
renderScript as $$renderScript, | ||
createMetadata as $$createMetadata | ||
} from "http://localhost:3000/"; | ||
|
||
export const $$metadata = $$createMetadata("/src/pages/index.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] }); | ||
|
||
const $$Index = $$createComponent(($$result, $$props, $$slots) => { | ||
|
||
return $$render`${$$maybeRenderHead($$result)}<main>${$$render`<script src="./hello.js"></script>`}</main>`; | ||
}, '/src/pages/index.astro', undefined); | ||
export default $$Index; | ||
``` | ||
--- |
41 changes: 41 additions & 0 deletions
41
internal/printer/__printer_js__/script_external_in_expression__renderScript__true_.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
[TestPrinter/script_external_in_expression_(renderScript:_true) - 1] | ||
## Input | ||
|
||
``` | ||
<main>{<script src="./hello.js"></script>} | ||
``` | ||
|
||
## Output | ||
|
||
```js | ||
import { | ||
Fragment, | ||
render as $$render, | ||
createAstro as $$createAstro, | ||
createComponent as $$createComponent, | ||
renderComponent as $$renderComponent, | ||
renderHead as $$renderHead, | ||
maybeRenderHead as $$maybeRenderHead, | ||
unescapeHTML as $$unescapeHTML, | ||
renderSlot as $$renderSlot, | ||
mergeSlots as $$mergeSlots, | ||
addAttribute as $$addAttribute, | ||
spreadAttributes as $$spreadAttributes, | ||
defineStyleVars as $$defineStyleVars, | ||
defineScriptVars as $$defineScriptVars, | ||
renderTransition as $$renderTransition, | ||
createTransitionScope as $$createTransitionScope, | ||
renderScript as $$renderScript, | ||
createMetadata as $$createMetadata | ||
} from "http://localhost:3000/"; | ||
|
||
export const $$metadata = $$createMetadata("/src/pages/index.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [{ type: 'external', src: './hello.js' }] }); | ||
|
||
const $$Index = $$createComponent(($$result, $$props, $$slots) => { | ||
|
||
return $$render`${$$maybeRenderHead($$result)}<main>${$$render`${$$renderScript($$result,"/src/pages/index.astro?astro&type=script&index=0&lang.ts")}`}</main>`; | ||
}, '/src/pages/index.astro', undefined); | ||
export default $$Index; | ||
``` | ||
--- |
41 changes: 41 additions & 0 deletions
41
internal/printer/__printer_js__/script_in_expression__renderScript__false_.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
[TestPrinter/script_in_expression_(renderScript:_false) - 1] | ||
## Input | ||
|
||
``` | ||
<main>{false && <script>console.log("hello")</script>} | ||
``` | ||
|
||
## Output | ||
|
||
```js | ||
import { | ||
Fragment, | ||
render as $$render, | ||
createAstro as $$createAstro, | ||
createComponent as $$createComponent, | ||
renderComponent as $$renderComponent, | ||
renderHead as $$renderHead, | ||
maybeRenderHead as $$maybeRenderHead, | ||
unescapeHTML as $$unescapeHTML, | ||
renderSlot as $$renderSlot, | ||
mergeSlots as $$mergeSlots, | ||
addAttribute as $$addAttribute, | ||
spreadAttributes as $$spreadAttributes, | ||
defineStyleVars as $$defineStyleVars, | ||
defineScriptVars as $$defineScriptVars, | ||
renderTransition as $$renderTransition, | ||
createTransitionScope as $$createTransitionScope, | ||
renderScript as $$renderScript, | ||
createMetadata as $$createMetadata | ||
} from "http://localhost:3000/"; | ||
|
||
export const $$metadata = $$createMetadata("/src/pages/index.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] }); | ||
|
||
const $$Index = $$createComponent(($$result, $$props, $$slots) => { | ||
|
||
return $$render`${$$maybeRenderHead($$result)}<main>${false && $$render`<script>console.log("hello")</script>`}</main>`; | ||
}, '/src/pages/index.astro', undefined); | ||
export default $$Index; | ||
``` | ||
--- |
41 changes: 41 additions & 0 deletions
41
internal/printer/__printer_js__/script_in_expression__renderScript__true_.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
[TestPrinter/script_in_expression_(renderScript:_true) - 1] | ||
## Input | ||
|
||
``` | ||
<main>{true && <script>console.log("hello")</script>} | ||
``` | ||
|
||
## Output | ||
|
||
```js | ||
import { | ||
Fragment, | ||
render as $$render, | ||
createAstro as $$createAstro, | ||
createComponent as $$createComponent, | ||
renderComponent as $$renderComponent, | ||
renderHead as $$renderHead, | ||
maybeRenderHead as $$maybeRenderHead, | ||
unescapeHTML as $$unescapeHTML, | ||
renderSlot as $$renderSlot, | ||
mergeSlots as $$mergeSlots, | ||
addAttribute as $$addAttribute, | ||
spreadAttributes as $$spreadAttributes, | ||
defineStyleVars as $$defineStyleVars, | ||
defineScriptVars as $$defineScriptVars, | ||
renderTransition as $$renderTransition, | ||
createTransitionScope as $$createTransitionScope, | ||
renderScript as $$renderScript, | ||
createMetadata as $$createMetadata | ||
} from "http://localhost:3000/"; | ||
|
||
export const $$metadata = $$createMetadata("/src/pages/index.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [{ type: 'inline', value: `console.log("hello")` }] }); | ||
|
||
const $$Index = $$createComponent(($$result, $$props, $$slots) => { | ||
|
||
return $$render`${$$maybeRenderHead($$result)}<main>${true && $$render`${$$renderScript($$result,"/src/pages/index.astro?astro&type=script&index=0&lang.ts")}`}</main>`; | ||
}, '/src/pages/index.astro', undefined); | ||
export default $$Index; | ||
``` | ||
--- |
This file contains 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
This file contains 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
This file contains 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