-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, excited for this!
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 Log
Build Log
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.directRenderScript
and 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.optimizeHoistedScript
option. 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!