Skip to content

Release v22.146.0

Choose a tag to compare

@github-actions github-actions released this 27 Oct 04:19
2fe9564

React components can now ask which module, feature and slice they are rendered in, resolved from the commands and queries in use, the slice folder they live in, or an explicit override, without passing anything down as props.

Added

  • useSliceContext() in @cratis/arc.react/slices returns the SliceLocation a component is rendered in, or SliceLocation.empty when nothing is known. See Slice context. (#3534)
  • <Slice> overrides the location for everything rendered within it, from location, module, feature or slice; without a location it is a boundary that keeps the commands and queries used within it from affecting the components outside it.
  • <Arc> provides a root slice scope, and useCommand, useQuery, useQueryWithPaging, useObservableQuery, useObservableQueryWithPaging, useChangeStream and the suspense query hooks register the slice location of their proxy on the nearest scope while mounted. When several slices are in use, the scope keeps the parts they agree on.
  • withViewModel in @cratis/arc.react.mvvm registers the slice locations of the commands and queries resolved for the view model.
  • useRegisterSliceLocation(location) for custom hooks that work with commands or queries without the Arc hooks, and withSliceLocation(component, location) to render a component within a scope for its slice folder.
  • SliceLocationPlugin in the new @cratis/arc.vite/slices entry point wraps exported components in slice folders so they render within a scope for their folder, with roots, segmentsToSkip, include, exclude and importFrom options. It keeps component names, refs, memo and React Fast Refresh working. See Resolve from slice folders at build time.
  • SliceLocation in @cratis/arc/reflection gains isEmpty and equals, and is re-exported from @cratis/arc.react/slices.