Repository navigation
Conversation
Made-with: Cursor
Made-with: Cursor # Conflicts: # packages/date/src/index.ts # packages/date/src/test/index.js
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +27 B (0%) Total Size: 7.74 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in ca02876. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24036439391
|
getSettings onlygetSettings only
|
I think it makes sense to split up these files a bit more for general maintainability and separation of concerns. 👍 On the overall approach, I don't love using a subpath export for this and I wish we could just have a better default experience. Would another way to go about this be to isolate the side effects into their own file(s) so that tree-shaking the root I also wonder: With the recent changes in #75831, do we even need the top-level |
|
@aduth I thought about this for a moment, and I think it won't be possible for me to achieve keeping the exported surface the same without a breaking change. Currently, importing the library in any way runs these side effects, and these side effects require moment.js. This behavior is basically part of the API of the library, and stopping it is a breaking change. |
But if I understand, the behavior is an expected part of the API through how it's used by the package's exported functions. So if those functions were to instead ensure the setup happens (has happened) lazily when called, they behave the same as they have previously. This is what I was expecting out of the In fact, if I follow the code, |
I'll also cc @epeicher & @jsnajdr because this seems like it could (should) have been done by virtue of the changes made in #75831. |
I'm totally down with that! I still think it's technically a breaking change, but it's probably fine. If someone imported the library like |
Could you explain a bit more what you'd expect to change? Maybe a practical example of a regression would be helpful. My impression is that the behavior doesn't change at all. |
|
Currently, the library is So if you have a library that has I'm not 100% confident, but that's is how I understand WP dependencies. |
|
Mmm, okay, I think I understand a bit better now that I'm looking at the code again. My impression was: It doesn't matter if WP timezone is set until something that uses it (i.e. a function within the package) is called. But in reality I guess we're working with a shared moment.js module, so defining the timezone is something that can be accessed by anyone working with WordPress's copy of moment.js, even outside the date package. So technically someone could load the That's a rather unfortunate setup, and maybe an exceedingly rare use-case, but it is indeed a behavior that existed 😞 |
|
Can you help me understand the use-case a bit better? I'm trying to follow whether the goal here is to get access to the "default" settings from how we'd expect the backend to behave (which could motivate a Is there any reason to introduce the "current" verbiage in these APIs, or could we just continue to use |
Absolutely. The motivation behind this PR was this. The Number Formatters library in Jetpack uses the And here's why using that global directly is a bad idea.
The only reason is I didn't want a clash between the root's |
Thanks for the context. It definitely helps. So is the main thing you're interested in is only the user locale from the date settings (source)? I wonder if there'd be a more direct way to get that. It's coming from I'm not strictly opposed to more direct access to the date package settings, though in this case it feels like you're generally not interested in the date package except for getting access to various backend settings that we expose through the package, and there may be alternative or more direct ways to get to those settings. |
|
You are right. I don't think this is worth changing the library over. I'll find an alternative. |
|
I think that might be the right choice for your given use-case, but I'll just say for posterity that I'd be willing to leave the door open for something like this in the future. It seems like |
Description
Consumers of
@wordpress/datethat only need access to the date settings (e.g.getSettings) are currently forced to bundlemomentandmoment-timezone(~300KB), because the entire module is evaluated on import — including top-level moment imports and asetupWPTimezone()call.This PR extracts the settings state into a new
settings.tsmodule with no moment dependency, and exposes it as a package subpath export:This import resolves to a module that only depends on
./types(which usesimport typefrom moment, erased at compile time), so bundlers won't include moment.js.The existing
getSettings()export from the main entry point continues to work unchanged — no deprecation, no breaking changes.Changes
packages/date/src/settings.ts: Contains thesettingsobject and exportsgetCurrentSettings()/setCurrentSettings(). No runtime dependencies on moment.packages/date/src/index.ts: Now imports from./settingsinstead of owning the settings state directly.getSettings()delegates togetCurrentSettings().packages/date/package.json: Added./settingssubpath export pointing to the built settings module (CJS, ESM, and types).getSettings()returns the same value asgetCurrentSettings(). Existing tests migrated to usegetCurrentSettings()directly.How has this been tested?
All existing
@wordpress/dateunit tests pass, including the new zone recovery tests from trunk.npm run test:unit -- --testPathPattern='packages/date/src/test'