-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 support for client:only
hydrator
#935
Conversation
🦋 Changeset detectedLatest commit: 10bc040 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This pull request is being automatically deployed with Vercel (learn more). astro-www – ./www🔍 Inspect: https://vercel.com/pikapkg/astro-www/4zAtNdT3Rb7WantKJsk4Y7tSuGWJ [Deployment for 10bc040 canceled] astro-docs – ./docs🔍 Inspect: https://vercel.com/pikapkg/astro-docs/6U8ms3QLsKE61YCBw5QUYV3roGS9 |
packages/astro/test/fixtures/astro-dynamic/src/pages/client-only.astro
Outdated
Show resolved
Hide resolved
Thanks @tony-sull ! One thing missing from this is, we need to remove the import statements when client:only is used. One of the main use-cases for using client:only is when a dependency doesn't work in Node.js I would create a test where a component depends on browser APIs... maybe it uses To remove the import statement might be a little tricky because we compile the JS part before walking the HTML AST. Discovery of components happens here: https://github.com/snowpackjs/astro/blob/main/packages/astro/src/compiler/codegen/index.ts#L441 However, we won't know that an import needs to be removed until we've walked the HTML AST and found the Idea: can we have would be wrapped in a function that only gets called after walking the HTML AST part. |
983e6e0
to
fc739c2
Compare
4a1d444
to
955b85f
Compare
955b85f
to
76fc406
Compare
Think I'm finally getting close on this one! Delaying the component imports took much more knowledge of Astro's compiler than I realized 😄 The last piece I think I'm missing is including the correct renderer without actually executing the client-only component on the server |
@tony-sull I think if you leave the import in at first the correct renderer will be added. Then remove it at the end of codegen. That's why I was suggesting to change the signature of that function to return a function rather than the JS string, that way you can modify the AST when walking the HTML part of the tree. Hope this helps. |
Thanks for your help here @matthewp! I may very well be misunderstanding a key bit here, but I'm not sure if that would do the trick for finding the right renderer. The import has to be removed before I ended up solving how to remove the import slightly differently and may need to move it to use the callback function mentioned, but I'm not quite sure yet how to have |
Will leave for others to review but overall +1 on this feature! Thanks for working to make it a reality, @tony-navillus ! |
…ere client:only imports must be removed
…nent import statements
8d606fe
to
7a9310e
Compare
@tony-sull is this ready to be merged? |
@matthewp Just pushed the final update to match renderers by full name (+ shorthand for The push ~30 min ago was just me rebasing from |
* Adding support for client:only hydration * Adding documentation for client:only * Adding changeset * Updating the test to use a browser-only API * Adding a browser-specific import script, this reproduces the issue where client:only imports must be removed * typo fix * removing mispelled test component * WIP: delaying inclusion of component imports until the hydration method is known * WIP: tweaking the test to use window instead of document * When only one renderer is included, use that for client:only hydration * temporary test script snuck into the last commit * WIP: adding check for a client:only renderer hint * refactor: Remove client:only components instead of delaying all component import statements * Updating the changeset and docs for the renderer hint * refactor: pull client:only render matching out to it's own function * Updating renderer hinting to match full name, with shorthand for internal renderers Co-authored-by: Tony Sullivan <[email protected]>
* wip * Add support for `client:only` hydrator (#935) * Adding support for client:only hydration * Adding documentation for client:only * Adding changeset * Updating the test to use a browser-only API * Adding a browser-specific import script, this reproduces the issue where client:only imports must be removed * typo fix * removing mispelled test component * WIP: delaying inclusion of component imports until the hydration method is known * WIP: tweaking the test to use window instead of document * When only one renderer is included, use that for client:only hydration * temporary test script snuck into the last commit * WIP: adding check for a client:only renderer hint * refactor: Remove client:only components instead of delaying all component import statements * Updating the changeset and docs for the renderer hint * refactor: pull client:only render matching out to it's own function * Updating renderer hinting to match full name, with shorthand for internal renderers Co-authored-by: Tony Sullivan <[email protected]> * [ci] yarn format * Update CONTRIBUTING.md (#1131) * [ci] yarn format * docs: fix select language in Safari (#1127) (#1128) * docs: fix select language in Safari (#1127) * docs: fix select language top position * docs: fix select language position * Make congratsbot not run in forks (#1145) * add back dark-mode aware favicons * make example favicons prefer non-dark mode * Version Packages (next) (#1129) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * code review comments Co-authored-by: Tony Sullivan <[email protected]> Co-authored-by: Tony Sullivan <[email protected]> Co-authored-by: matthewp <[email protected]> Co-authored-by: FredKSchott <[email protected]> Co-authored-by: Oleg <[email protected]> Co-authored-by: Marcus Otterström <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
* Adding support for client:only hydration * Adding documentation for client:only * Adding changeset * Updating the test to use a browser-only API * Adding a browser-specific import script, this reproduces the issue where client:only imports must be removed * typo fix * removing mispelled test component * WIP: delaying inclusion of component imports until the hydration method is known * WIP: tweaking the test to use window instead of document * When only one renderer is included, use that for client:only hydration * temporary test script snuck into the last commit * WIP: adding check for a client:only renderer hint * refactor: Remove client:only components instead of delaying all component import statements * Updating the changeset and docs for the renderer hint * refactor: pull client:only render matching out to it's own function * Updating renderer hinting to match full name, with shorthand for internal renderers Co-authored-by: Tony Sullivan <[email protected]>
RFC #751
Changes
Adding support for
client:only
hydration to skip components during SSRTesting
The
astro-dynamic.test.js
suite was updated to include test coverage for:client:only
components are skipped during SSRDocs
Component hydration docs have been updated to include
client:only