Skip to content
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

Module augmentation prefactorings #1616

Merged
merged 33 commits into from
May 21, 2024
Merged

Conversation

nvie
Copy link
Collaborator

@nvie nvie commented May 16, 2024

This preps the Liveblocks context module by removing all remaining closures from the bundle factory, move all closed-over hooks to the top level and parameterize them all with a client instance. This will pave the way for the addition of the new top-level hooks.

Note

💡 Best reviewed commit-by-commit to see each refactoring step!

This PR should be possible to be merged as-is, because no behavioral changes are expected here.

@marcbouchenoire I'd appreciate if you could manually double-check this work, by running a couple smoke tests manually here. I have run all the unit tests, but this particular part of the code base is not 100% covered.

I'll make a similar changes to the Room context factory tomorrow — but there are a lot more of those there, so I first want to get you on board with this subset.

@nvie nvie self-assigned this May 16, 2024
Copy link

vercel bot commented May 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
examples-nextjs-comments-audio ⬜️ Ignored (Inspect) Visit Preview May 21, 2024 10:57am
examples-nextjs-comments-canvas ⬜️ Ignored (Inspect) Visit Preview May 21, 2024 10:57am
examples-nextjs-comments-notifications ⬜️ Ignored (Inspect) Visit Preview May 21, 2024 10:57am

Copy link
Contributor

@GuillaumeSalles GuillaumeSalles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, no behavioral changes. But the order of notifications is changing in a unit test, but I couldn't figure out why just by looking at the code. 🤔

@nvie
Copy link
Collaborator Author

nvie commented May 17, 2024

Oh, this is a unit test that I have seen occasionally fail on main, even before I started all the refactorings. I think this test is just not deterministic, but I doubt it’s a real issue. I’ll look into it.

❌ First run is failing
✅ Re-running it makes it pass

@nvie
Copy link
Collaborator Author

nvie commented May 17, 2024

@marcbouchenoire Do you have an idea what can cause the alternative ordering of those inbox notifications? Are we maybe missing an explicit sort on the backend side?

@marcbouchenoire
Copy link
Collaborator

Do you have an idea what can cause the alternative ordering of those inbox notifications? Are we maybe missing an explicit sort on the backend side?

@nvie Maybe the non-deterministic nature is due to timing? In the failing test I see the dummy notifications' timestamps slightly different, which makes sense since they're created one after another (2024-05-16T22:12:53.561Z vs 2024-05-16T22:12:53.562Z), maybe there are cases/cycles where the timestamps align and the notifications get sorted differently because of that?

@nvie nvie requested a review from CTNicholas as a code owner May 17, 2024 11:43
@nvie nvie force-pushed the module-augmentation-prefactorings branch from 752c82b to 911c5af Compare May 17, 2024 11:43
@nvie nvie force-pushed the module-augmentation-prefactorings branch from 406e984 to 9c2108b Compare May 17, 2024 15:36
/**
* @private
*
* This is an internal API, use `createRoomContext` instead.
*/
export function useRoomContextBundleOrNull() {
const client = useClientOrNull();
return client === null ? null : getOrCreateRoomContextBundle(client);
const room = useRoomOrNull();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key line for this fix. useRoomContextBundleOrNull() isn't really dependent on having a room in order to create the bundle, but… the way the useSharedBundle() function works is that it only expects this function to return a result if a RoomProvider context is active. This was a tricky one! Super glad you discovered this, @marcbouchenoire.

Next week, I'll ensure that the E2E page/test will also capture this edge case before I continue to refactor more.

@nvie nvie force-pushed the module-augmentation-prefactorings branch from 9c2108b to 1d2e833 Compare May 20, 2024 07:50
@nvie
Copy link
Collaborator Author

nvie commented May 20, 2024

Maybe the non-deterministic nature is due to timing?

@marcbouchenoire Yeah, maybe. I just added ebd6ab2 which sorts the arrays before comparing them. I really wish there was a native matcher for this in Jest.

@nvie nvie force-pushed the module-augmentation-prefactorings branch from 29bbb87 to ebd6ab2 Compare May 20, 2024 12:10
@liveblocks liveblocks deleted a comment from vercel bot May 20, 2024
@liveblocks liveblocks deleted a comment from vercel bot May 20, 2024
@liveblocks liveblocks deleted a comment from vercel bot May 20, 2024
@liveblocks liveblocks deleted a comment from vercel bot May 20, 2024
Copy link
Collaborator

@marcbouchenoire marcbouchenoire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@nvie nvie merged commit c5b27bf into main May 21, 2024
59 of 60 checks passed
@nvie nvie deleted the module-augmentation-prefactorings branch May 21, 2024 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants