-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix(tldraw): enable initial currentPageId prop #857
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
d906470
to
08ca59b
Compare
Wow, I spent some time working on this today and it really is a thorny issue. See what you can come up with, I'll also try some things out here. |
08ca59b
to
b74d081
Compare
@steveruizok I spent more time on this today than I'd care to admit 😆 but I think I've come up with something that feels pretty good Still need to actually play around with the changes in the example app just to make sure it's working the way I think it will, but gonna call it a day so will hopefully get a chance to do that tomorrow |
Played around with it, seems to be working! |
Actually I wasn't thorough enough with testing. It works fine if If you have multiple pages and tldraw/packages/tldraw/src/state/TldrawApp.ts Lines 1351 to 1363 in ecb4bfc
It works if I don't reset |
b74d081
to
89992f3
Compare
In the current state, we can at least pass an Shared more detailed thoughts in tldraw/tldraw-v1#187 |
It might need to be for now. Quite frustrating due to the need to wait for the async indexeddb load. |
I was thinking about fixing this too, quite frustrating when it always comes back to the first page. I think you can do that IMO |
Sorry this has been languishing! Will try to get it updated and ready for merge later today. Gonna go with the |
This PR fixes tldraw/tldraw-v1#187
Opening this as a draft because I'm really not sure what the best approach would be here.
tldraw/tldraw-v1#187 occurs because
TldrawApp
initializes its state fromTldrawApp.defaultState
which doesn't reflect the reality of our intentions if we're passing customdocument
/currentPageId
props toTldraw
:Us: Hey
Tldraw
, please renderpage1
from ourcustomDocument
Tldraw
: Sure thing! Renderingpage
fromTldrawApp.defaultDocument
For an initial attempt, I added a third
initialState
argument toTldrawApp#constructor
that defaults toTldrawApp.defaultState
. I then added a new object in the initializers inTldraw
usingTldrawApp.defaultState
, overriding specifically thedocument
andappState.currentPageId
keys since those are the only parts of initial state relevant toTldraw
.This allows us to set the custom initial state we need without any breaking changes. The downside is that the initialization piece is gross af imo. Consumers probably shouldn't need to spread
TldrawApp.defaultState
like that, but I couldn't think of a better way to handle it.I had considered making
initialState
optional and deep merging it intoTldrawApp.defaultState
when provided, but since we need to replacedefaultState.document
withprops.document
if it exists, deep merging isn't an option here. We could make the new argument an object of type{ document: TDDocument; currentPageId: string }
and do the spreading ourselves insideTldrawApp
, but that feels too specific to only theTldraw
use case.Would love some additional thoughts or context to help shape this into a better solution!