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

Add back lib export #923

Closed
wants to merge 4 commits into from
Closed

Add back lib export #923

wants to merge 4 commits into from

Conversation

NerdCowboy
Copy link

Fixes #903

There still may be issues with SSR per #903 (comment). I assume that issue is related to the wildcard export, so I manually exported everything instead.

@itsmichaeldiego
Copy link
Member

itsmichaeldiego commented Aug 24, 2020

@NerdCowboy Hey! Thanks for the PR, I've tried this but then the issue is #901 starts again, the problem is when you export named and default imports with SSR.

You can create a simple project using Next.JS and try it yourself, or try it in this codesandbox.

I haven't found the best way to do it yet, I am happy to work together with you. I was checking at this solution but haven't tried yet: https://stackoverflow.com/a/51519513/4949445

@NerdCowboy
Copy link
Author

NerdCowboy commented Aug 24, 2020

@itsmichaeldiego I did some debugging and confirmed the issue appears to be using default and named exports in the same file. If I covert the default export GoogleMap to a named export, everything works just fine.

Ignore my commit name on the last push, it does not actually fix the issue entirely, but it does fix it if you consume GoogleMap as a named export.

Obviously not ideal as it's a breaking change, but I'll try to look into this issue more later.

@itsmichaeldiego
Copy link
Member

itsmichaeldiego commented Aug 25, 2020

That would be amazing, thanks @NerdCowboy

This way it would work with NextJS only if its named imported, right?

@itsmichaeldiego
Copy link
Member

@NerdCowboy If you look at the latest stable version 1.1.7: https://github.com/google-map-react/google-map-react/tree/1.1.7
both ways were working fine, I think we should check how things were being built back then in order to make a proper fix

@NerdCowboy
Copy link
Author

The issue appears to be with Microbundle. They don't support and seem to actively discourage using mixed named and default exports per developit/microbundle#306. I tried the workaround suggested, but it didn't work for me as it looks like the exports var gets renamed when compiled, so it's never exported.

I think React Helmet might have also been bit by this issue, so I'm guessing it's more of a Rollup issue since Microbundle also uses Rollup. nfl/react-helmet#547. They initially only used named exports, but ended using both a named and default export. nfl/react-helmet#395

Not sure what you want to do here. From what I see, here's the options:

  • Move off of Microbundle
  • Convert default export to named export (could use both named & default, but wouldn't recommend due to default not working with SSR)
  • Force the consumer to pull in the lib methods directly from the sub-directory like it was prior to 2.0

Since 2.0 came with breaking changes and 2.0+ itself has technically been broken since its release for anyone using lib methods, I think the path of least resistance would be to convert the default export to a named one.

For what it's worth, a lot of people are starting to push for only using named exports
https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/
https://basarat.gitbook.io/typescript/main-1/defaultisbad

Let me know what you think

@itsmichaeldiego
Copy link
Member

Thanks for your research, its super helpful, I didn't know it was a problem with microbundle itself. I did see this problem with rollup though, and I was thinking the only way was to change microbundle to another similar technology.

Let me get this straight, you recommend that we convert the default export to a named one for SSR or in general?

@NerdCowboy
Copy link
Author

No problem. I'm recommending converting the default export to use a named one only.

In general, I think the arguments for using only named exports are pretty sound, but I'm not recommending refactoring any other default exports unless you think it's possible you'll want to add named exports from the same file in the future.

Up to you what you want to do though. Just let me know and I'll update my PR or if you want to tackle it, that's cool too.

@karldanninger
Copy link
Member

I agree with @NerdCowboy, even though it's not ideal - it may be the way to go moving forward!

@itsmichaeldiego
Copy link
Member

itsmichaeldiego commented Aug 30, 2020

@NerdCowboy @karldanninger I agree with you both, I am just worried that we're not providing backwards compatibility for those people using SSR + default import. Instead we're breaking it.

I think we should do these steps:

  • Force the consumer to pull in the lib methods directly from the sub-directory like it was prior to 2.0 (fixes the issue)
  • Move out from microbundle (I can take care of that)
  • Slowly move to named export, by using backwards compatibility and a warning message (if we moved out from microbundle this should be easy to do)

@itsmichaeldiego
Copy link
Member

@NerdCowboy @karldanninger Hey folks, I've opened a new issue in microbundle: developit/microbundle#712 and I got an answer, will try that and let you know

@karldanninger
Copy link
Member

You're the man @itsmichaeldiego! 💪💪

I'm glad they gave a useful response on the issue.

@itsmichaeldiego
Copy link
Member

This was fixed and released in 2.1.3, please let me know if it works!! 🙏

Sorry for the delay! Thanks to both of you!

@karldanninger @NerdCowboy 🙏

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.

Can't import fitBounds from google-map-react
3 participants