-
Notifications
You must be signed in to change notification settings - Fork 523
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
feat(InstantSearch): add in dev timeout when start is not called #3238
feat(InstantSearch): add in dev timeout when start is not called #3238
Conversation
Deploy preview for algolia-instantsearch ready! Built with commit d2a93e6 https://deploy-preview-3238--algolia-instantsearch.netlify.com |
Thanks a lot! This was the initial way I was thinking. @francoischalifour, do you have any idea how we can make this work with CDN? Maybe we should add a dev bundle 🤔 I think it would be worth it, so we can ship minified error messages too |
src/lib/InstantSearch.js
Outdated
this._widgetTimer = setTimeout( | ||
() => | ||
// eslint-disable-next-line no-console | ||
console.warn( |
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.
NOTE: in v3 this will need to be changed to the logger function we added for consistency
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.
It's already available in v2: https://github.com/algolia/instantsearch.js/blob/develop/src/lib/utils.js#L426
@HeroProtagonist You can replace console.warn
with this utility function :)
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.
In the constructor, console.warn
is called a few times (I copied log format from there). Would you want me to add the utility function in those places as well?
https://github.com/algolia/instantsearch.js/blob/develop/src/lib/InstantSearch.js#L137
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.
Sure, feel free to update those in another PR!
Thank you @HeroProtagonist! @Haroenv I've got some plans on creating a development and production bundle. I'm not sure when this can fit in our roadmap though. I think we should wait for these new bundles before adopting this new strategy and only include it in the development bundle. |
Since this is actually a fairly low amount of code, and only a single timer, I think we could add this code as-is |
It would be the first time using Waiting to include this in the actual user bundle would provide much more value. What do you think? |
Thanks for the work @HeroProtagonist! But I agree with @francoischalifour I would prefer to wait until we have a proper support of development / production bundle too. We can tackle all those issues related to the DX once we have setup a proper build chain for development / production. |
I updated the pr to use I did notice that no where else in the file |
We will leave this PR on hold for now, waiting for better strategies on our side to handle development-only features. Thank you for your work, this is greatly appreciated. |
The `warn` utility function should be used over calling `console.warn` directly See discussion: #3238 (comment)
Follow up on this PR – we introduced a way to execute code only in development enviroment with #3260, using the global We however decided not to move forward with this development feature because we haven't really felt the pain of forgetting to call Thank you for your contribution though, it made us realize the need for development-only features earlier than originally planned. |
Summary
Closes #2671
When
NODE_ENV === 'development'
andthis.started
has not been set. A new timer will be set each timeaddWidgets
is called. Only one timer is ever active and whenthis.started
is called, it will be cleared.Result
When widgets are added during development with
yarn dev
if.start()
is not called within 5 seconds a warning will be displayed in the console.