-
- Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: hydratable and friends #16960
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
Open
elliott-with-the-longest-name-on-github wants to merge 57 commits into main Choose a base branch from elliott/resources
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
feat: hydratable and friends #16960
Changes from all commits
Commits
Show all changes
57 commits Select commit Hold shift + click to select a range
da3260f checkpoint; hydratable and base resource work
elliott-with-the-longest-name-on-github 4d766f8 checkpoint
elliott-with-the-longest-name-on-github 7c8c1ad maximum hydration
elliott-with-the-longest-name-on-github 83643ce upgrade devalue
elliott-with-the-longest-name-on-github 61d02fe Merge remote-tracking branch 'origin' into elliott/resources
elliott-with-the-longest-name-on-github bca87b9 checkpoint
elliott-with-the-longest-name-on-github 82be388 chore: temporarily remove fetcher
elliott-with-the-longest-name-on-github 25210c2 types
elliott-with-the-longest-name-on-github 9c7da6c only generate hydratables when there's some amount of content
elliott-with-the-longest-name-on-github 5de6383 add hash
elliott-with-the-longest-name-on-github 8449ea7 making progress i think
elliott-with-the-longest-name-on-github ef11dae typegen
elliott-with-the-longest-name-on-github d36894a it at least basically works
elliott-with-the-longest-name-on-github 0c4ce5a misc improvements
elliott-with-the-longest-name-on-github a2bff0c split stuff out, fix treeshaking
elliott-with-the-longest-name-on-github 2e292b1 cache observer
elliott-with-the-longest-name-on-github 7ee0ce8 fix export
elliott-with-the-longest-name-on-github 90b85d1 add imperative hydratable API
elliott-with-the-longest-name-on-github 598dc30 fix types
elliott-with-the-longest-name-on-github 2c08d4f fix types
elliott-with-the-longest-name-on-github 5adb3f1 test
elliott-with-the-longest-name-on-github 8179c6a tests
elliott-with-the-longest-name-on-github 6873685 temp fix
elliott-with-the-longest-name-on-github 8939bbf fix never-expiring cache entries
elliott-with-the-longest-name-on-github 0f6001d misc
elliott-with-the-longest-name-on-github 8667dab Merge remote-tracking branch 'origin' into elliott/resources
elliott-with-the-longest-name-on-github 200b011 types
elliott-with-the-longest-name-on-github 816ddca import
elliott-with-the-longest-name-on-github 7d44a1d remove cruft, fix some type errors
elliott-with-the-longest-name-on-github cc094c5 .js .js .js wah wah wah
elliott-with-the-longest-name-on-github c6da91f if you ignore your problems they go away
elliott-with-the-longest-name-on-github b36ba6d unused
elliott-with-the-longest-name-on-github d6f240a better serialization
elliott-with-the-longest-name-on-github 7d0451e oops
elliott-with-the-longest-name-on-github cd7a71f oops
elliott-with-the-longest-name-on-github 0581bb9 tweak
elliott-with-the-longest-name-on-github 5aa7598 tweak
elliott-with-the-longest-name-on-github 08d755b tweak
elliott-with-the-longest-name-on-github 9a424cd add errors
elliott-with-the-longest-name-on-github e28ced7 tweak hydratable API, add official errors
elliott-with-the-longest-name-on-github aaf2eb8 fix types
elliott-with-the-longest-name-on-github 555e950 Merge remote-tracking branch 'origin' into elliott/resources
elliott-with-the-longest-name-on-github d5fef8b types
elliott-with-the-longest-name-on-github 3f24dd2 Update packages/svelte/src/internal/server/renderer.js
elliott-with-the-longest-name-on-github 551572e errors
elliott-with-the-longest-name-on-github 998510c Merge branch 'elliott/resources' of github.com:sveltejs/svelte into e…
elliott-with-the-longest-name-on-github f9123f4 Update packages/svelte/messages/client-errors/errors.md
elliott-with-the-longest-name-on-github d5e4af8 fixes
elliott-with-the-longest-name-on-github 61706dd Merge branch 'elliott/resources' of github.com:sveltejs/svelte into e…
elliott-with-the-longest-name-on-github 0ff9656 fix
elliott-with-the-longest-name-on-github 1a6b53b chore: use public.d.ts as entry point for svelte/reactivity (#17124)
Rich-Harris 141fd1e reactive cache
elliott-with-the-longest-name-on-github eca531f Merge branch 'elliott/resources' of github.com:sveltejs/svelte into e…
elliott-with-the-longest-name-on-github f9cdb76 caching
elliott-with-the-longest-name-on-github a715fa1 chore: tweak resource implementation (#17123)
Rich-Harris cc74b6d Merge branch 'elliott/resources' of github.com:sveltejs/svelte into e…
elliott-with-the-longest-name-on-github 85abdbd whatever
elliott-with-the-longest-name-on-github File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /** @import { Decode, Hydratable, Transport } from '#shared' */ | ||
| import { async_mode_flag } from '../flags/index.js'; | ||
| import { hydrating } from './dom/hydration.js'; | ||
| import * as w from './warnings.js'; | ||
| import * as e from './errors.js'; | ||
| | ||
| /** | ||
| * @template T | ||
| * @param {string} key | ||
| * @param {() => T} fn | ||
| * @param {Transport<T>} [options] | ||
| * @returns {T} | ||
| */ | ||
| function isomorphic_hydratable(key, fn, options) { | ||
| if (!async_mode_flag) { | ||
| e.experimental_async_required('hydratable'); | ||
| } | ||
| | ||
| return access_hydratable_store( | ||
| key, | ||
| (val, has) => { | ||
| if (!has) { | ||
| w.hydratable_missing_but_expected(key); | ||
elliott-with-the-longest-name-on-github marked this conversation as resolved. Show resolved Hide resolved | ||
| return fn(); | ||
| } | ||
| return decode(val, options?.decode); | ||
| }, | ||
| fn | ||
| ); | ||
| } | ||
| | ||
| isomorphic_hydratable['get'] = get_hydratable_value; | ||
| isomorphic_hydratable['has'] = has_hydratable_value; | ||
| isomorphic_hydratable['set'] = () => e.fn_unavailable_on_client('hydratable.set'); | ||
| | ||
| /** @type {Hydratable} */ | ||
| const hydratable = isomorphic_hydratable; | ||
| Comment on lines +36 to +37 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the indirection? why not Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the only way I could figure out to type it correctly | ||
| | ||
| export { hydratable }; | ||
| | ||
| /** | ||
| * @template T | ||
| * @param {string} key | ||
| * @param {{ decode?: Decode<T> }} [options] | ||
| * @returns {T | undefined} | ||
| */ | ||
| function get_hydratable_value(key, options = {}) { | ||
| if (!async_mode_flag) { | ||
| e.experimental_async_required('hydratable.get'); | ||
| } | ||
| | ||
| return access_hydratable_store( | ||
| key, | ||
| (val) => decode(val, options.decode), | ||
| () => undefined | ||
| ); | ||
| } | ||
| | ||
| /** | ||
| * @param {string} key | ||
| * @returns {boolean} | ||
| */ | ||
| function has_hydratable_value(key) { | ||
| if (!async_mode_flag) { | ||
| e.experimental_async_required('hydratable.set'); | ||
| } | ||
| return access_hydratable_store( | ||
| key, | ||
| (_, has) => has, | ||
| () => false | ||
| ); | ||
| } | ||
| | ||
| /** | ||
| * @template T | ||
| * @param {string} key | ||
| * @param {(val: unknown, has: boolean) => T} on_hydrating | ||
| * @param {() => T} on_not_hydrating | ||
| * @returns {T} | ||
| */ | ||
| function access_hydratable_store(key, on_hydrating, on_not_hydrating) { | ||
| if (!hydrating) { | ||
| return on_not_hydrating(); | ||
| } | ||
| var store = window.__svelte?.h; | ||
| return on_hydrating(store?.get(key), store?.has(key) ?? false); | ||
| } | ||
| | ||
| /** | ||
| * @template T | ||
| * @param {unknown} val | ||
| * @param {Decode<T> | undefined} decode | ||
| * @returns {T} | ||
| */ | ||
| function decode(val, decode) { | ||
| return (decode ?? ((val) => /** @type {T} */ (val)))(val); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.