Add experimental.directRenderScript option#10102
Conversation
🦋 Changeset detectedLatest commit: 781afc5 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
We should update the PR, and replace the compiler dependency with the correct one |
|
!preview direct-render-script |
|
Snapshots have been released for the following packages:
Publish LogBuild Log |
sarah11918
left a comment
There was a problem hiding this comment.
Thanks, @bluwy ! Took a pass at the changeset, mostly because I wanted to make sure it explicitly addressed removing the old option (whether or not they added the new one) since it's deleted from the docs (and, I'm assuming from the codebase? But could be wrong about that! Even if not, just as well to tell people the option is deleted and force them on to the new one! 😄 )
When we have the wording from the changeset finalized, I will take a look at the JSdoc again, just for consistency in case anything changes! 🙌
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
sarah11918
left a comment
There was a problem hiding this comment.
Looks good to me, @bluwy ! 🙌
Changes
Relies on withastro/compiler#969, The PR should be merged and released and updated here before merging.
Closes #7857 (Styles will be tackled separately)
This introduces
experimental.directRenderScriptand removesexperimental.optimizeHoistedScript. Both work differently but should achieve the same result. When directly rendering scripts, it will no longer be hoisted and will be rendered where it's declared. The compiled code will call${renderScript($$result, "/src/pages/...")}to render the script.This option is introduced due to the current caveats of our script handling. Today, it works by starting from each Astro pages, and crawling the module graph to find the imported Astro components's scripts, and include it to the Astro page. However, this is not ideal in many cases if Astro components are only used conditionally, or through barrel files, resulting in scripts added to a page when it shouldn't.
This new option prevents the caveat by only including the scripts when the components are actually rendered. That way it won't be possible for scripts to be included in a page that it shouldn't.
Testing
Lend the tests from the
experimental.optimizeHoistedScriptoption. I also tested enabling the option by default, and it seems to mostly work besides the known caveats,Docs
Added a changeset and jsdoc. Needs a review on this!