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

Patch Leaflet to be Server-Side-Render friendly (SSR) #9316

Closed
wants to merge 3 commits into from

Conversation

matthova
Copy link
Contributor

@matthova matthova commented Apr 6, 2024

This Pull request adds the eslint plugin ssr-friendly and implements changes to meet the new linting requirements.

I've confirmed I'm able to use the forked library with a SSR Remix app.

@@ -2,85 +2,92 @@
hljs.configure({tabReplace: ' '});
hljs.initHighlighting();

const tocCopy = document.createElement('div');
tocCopy.id = 'toc-copy';
function setup() {
Copy link
Member

Choose a reason for hiding this comment

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

Anything in docs/ will only ever run in a browser. You made the blanket assumption that all .js files are part of the Leaflet code, but some are part of its website. These changes are therefore too broad.

mac,
linux
};
export default setupBrowser();
Copy link
Member

Choose a reason for hiding this comment

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

This breaks tree-shaking (which, from my PoV, is more important than SSR friendlyness)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good callout. I'll see if there's a way to have both

const pointer = !!window.PointerEvent;
// @property pointer: Boolean
// `true` for all browsers supporting [pointer events](https://msdn.microsoft.com/en-us/library/dn433244%28v=vs.85%29.aspx).
const pointer = !!window.PointerEvent;
Copy link
Member

Choose a reason for hiding this comment

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

You may use something like !!(window?.PointerEvent). Ditto for navigator and the like.

@IvanSanchez
Copy link
Member

@matthova
Copy link
Contributor Author

matthova commented Apr 6, 2024

@IvanSanchez thank you for the feedback! I love the idea of enforcing ssr-compatibility via the lint plugin I added, however, I wonder if there's a slightly different approach we could take for this library to remove unnecessary function-wrapping. Let me do some digging

@jonkoops
Copy link
Collaborator

jonkoops commented Apr 6, 2024

I've confirmed I'm able to use the forked library with a SSR Remix app.

I am curious about this. Why would Leaflet need to be 'SSR friendly' in order for this to work? Leaflet was always intended to be a complete client-side solution, so why even use it in an SSR context? Can Remix not opt-out of SSR for the few places one might need to include Leaflet?

@matthova
Copy link
Contributor Author

matthova commented Apr 6, 2024

I've confirmed I'm able to use the forked library with a SSR Remix app.

I am curious about this. Why would Leaflet need to be 'SSR friendly' in order for this to work? Leaflet was always intended to be a complete client-side solution, so why even use it in an SSR context? Can Remix not opt-out of SSR for the few places one might need to include Leaflet?

That's a great question. I think the maintainers of the library need to own this decision. My use case, as a consumer, is that I love being able to install a package and not have to think about it or do any additional configuration. The tradeoff may not be worth it, for maintainers.

@matthova
Copy link
Contributor Author

matthova commented Apr 6, 2024

Closing and will submit an alternate approach with optional chaining

@matthova matthova closed this Apr 6, 2024
@matthova matthova mentioned this pull request Apr 6, 2024
@matthova
Copy link
Contributor Author

matthova commented Apr 6, 2024

Alternate PR: #9317

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