Allow Mithril to be loaded in non-browser environments without modification #2633
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Recast the global reads to all be guarded with
typeof
, so that if they aren't defined, they're justnull
.Note that this does not involve documentation changes, as that's going to require a lot more effort and is best left as a follow-up. (Our support for this is undocumented anyways, and the relevant docs are for hooking it up with JSDOM. This only really matters in practice if you're using
mithril-node-render
.)Motivation and Context
This has been a fairly common gotcha, and I'd like to actually fix it rather than repeatedly tell users how to work around it in about 2-3 different ways (depending on how they test their app). This in effect moves that workaround into core, but without polluting the global scope like #2613.
Closes #2613
How Has This Been Tested?
Ran
require("./.")
in the package root from a fresh Node REPL and no errors occurred.Types of changes
Checklist:
docs/changelog.md