-
Notifications
You must be signed in to change notification settings - Fork 9
fix: use preloaded data in useDoc #1096
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
Conversation
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.
Pull Request Overview
This PR fixes the useDoc hook by removing the defaultValue parameter and instead returning the preloaded data from window.sourceData.
- Removed the defaultValue parameter from useDoc and its related effect block
- Updated the return logic to use preloaded data instead of a default value
Comments suppressed due to low confidence (1)
jumble/public/module/charm/sandbox/bootstrap.js:11
- Removing the defaultValue parameter changes the fallback behavior of useDoc. Confirm that all callsites have been updated to rely on window.sourceData for preloaded data instead of passing a default value.
window.useDoc = function (key) {
|
@seefeldb would be great to get your input on this because we went back and forth in regards to what we want to do if key was not preloaded here https://linear.app/common-tools/issue/CT-308/usedoc-should-return-data-read-from and https://discord.com/channels/1232452732963655720/1252747522678460466/1364692637533208727 I also have since realized that |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
I originally wanted to achieve this kind of behaviour by blocking the initial React render until we had received the first copy of the Charm's data, then useDoc wouldn't need to have such complex fallback behaviour.
This PR seems cleaner to me in achieving some of that, but I actually don't know how to protect against stale data completely... not without @seefeldb's input
|
Were you able to verify what happens when the schema defines a key, where the value undefined is allowed (e.g. an optional key with no default value) and it is undefined? Will sourceData include it? |
|
Ah, since we're not throwing, this is fine. One thing to watch for: The way to set default values is via the schema, but if the LLM doesn't do that, then it might instead use useEffect, which might exacerbate the issues. |
Perhaps alternative tack would be to kickoff schema alteration when |
Per https://linear.app/common-tools/issue/CT-308/usedoc-should-return-data-read-from