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

Allow waiting on a preload #305

Closed
wants to merge 1 commit into from
Closed

Conversation

crisvergara
Copy link

Summary

Allow waiting on preload.

My main use case is to prevent displaying a fallback when routing between pages. Example:

const wait = ms => new Promise((resolve) => setTimeout(resolve, ms));
await Promise.race([MyLoadableComponent.preload(), wait(100)])
showPage();

@theKashey
Copy link
Collaborator

🤪 #285, #226 😭

@gregberge
Copy link
Owner

I should reconsider it, if it happens it will be a load method, but I am afraid that it is not the philosophy recommended by Suspense.

@gregberge gregberge closed this Apr 12, 2019
@crisvergara
Copy link
Author

I understand you're hemming close to React, but I guess this is a case where I find myself strongly disagreeing with their philosophy. Flashing a loading state is bad, but the p-min-delay solution of forcing a loading state is not a real fix either. Both create a navigation experience that looks unprofessional.

I'm going to use the work-around specified here: #226 (comment)

@gregberge
Copy link
Owner

Yeah it is a good workaround. The best workaround would be to use the fallback. If the fallback is displayed, then you are waiting. When it is hidden, then you are done.

That being said, you could use a useEffect in the fallback that notify the « wait » and the « done ».

Using this method, you could wait for anything, data, nested loaded components...

But yes you have to render the component to know if you are waiting or not. In a project, I did it with a hidden router. I should probably release something about it.

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.

3 participants