@rebasepro/ui 0.14.1 → 0.14.2-canary.gca521e9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./views";
3
3
  export * from "./icons";
4
4
  export * from "./styles";
5
5
  export { cls } from "./util/cls";
6
+ export { lazyChunk, loadChunk, isChunkLoadError } from "./util/lazy_chunk";
6
7
  export { CHIP_COLORS, CHIP_HUES, CHIP_SEED_KEYS, getColorSchemeForKey, getColorSchemeForSeed } from "./util/chip_colors";
7
8
  export type { ChipHue, ChipTone } from "./util/chip_colors";
8
9
  export { useOutsideAlerter } from "./hooks/useOutsideAlerter";
package/dist/index.es.js CHANGED
@@ -3126,8 +3126,107 @@ function CircularProgressCenter({ text, ...props }) {
3126
3126
  });
3127
3127
  }
3128
3128
  //#endregion
3129
+ //#region src/util/lazy_chunk.ts
3130
+ /**
3131
+ * Dynamic imports that survive a redeploy.
3132
+ *
3133
+ * A built SPA names its chunks by content hash and a deploy replaces the whole
3134
+ * `assets/` directory, so a tab opened before the deploy still holds the *old*
3135
+ * entry chunk. The first lazy route that tab opens asks for a hash that no
3136
+ * longer exists on the server, the import rejects, and the view is dead until
3137
+ * the user thinks to reload — which nothing on screen tells them to do. The
3138
+ * browser's own wording ("Failed to fetch dynamically imported module: …") reads
3139
+ * like a build bug, so this is usually reported as one.
3140
+ *
3141
+ * `loadChunk` retries once — that covers a transient network failure — and then
3142
+ * gives up with an error tagged as a chunk load failure, so `ErrorBoundary` can
3143
+ * offer a reload instead of printing the browser's message.
3144
+ */
3145
+ /**
3146
+ * Marker property set on the error thrown after a failed retry. Read by
3147
+ * `isChunkLoadError`, which is what the UI matches on.
3148
+ */
3149
+ var CHUNK_LOAD_ERROR_FLAG = "rebaseChunkLoadError";
3150
+ /**
3151
+ * Each engine words this differently, and the message is the only signal — none
3152
+ * of them use a distinguishable error type. The MIME variants matter as much as
3153
+ * the fetch ones: a server whose SPA fallback answers a missing `/assets/x.js`
3154
+ * with `index.html` returns 200 HTML, and the browser rejects it as a module.
3155
+ */
3156
+ var CHUNK_ERROR_PATTERNS = [
3157
+ "failed to fetch dynamically imported module",
3158
+ "error loading dynamically imported module",
3159
+ "importing a module script failed",
3160
+ "failed to load module script",
3161
+ "expected a javascript",
3162
+ "unable to preload css"
3163
+ ];
3164
+ /**
3165
+ * Does this error mean a chunk could not be loaded — rather than the chunk's
3166
+ * own code throwing once it did load?
3167
+ *
3168
+ * Errors raised anywhere are matched, not just ones `loadChunk` produced: React
3169
+ * `lazy()` calls that still import directly, and Vite's own CSS preloads, fail
3170
+ * the same way and deserve the same recovery.
3171
+ */
3172
+ function isChunkLoadError(error) {
3173
+ if (!error || typeof error !== "object") return false;
3174
+ if (error[CHUNK_LOAD_ERROR_FLAG] === true) return true;
3175
+ const message = error.message;
3176
+ if (typeof message !== "string") return false;
3177
+ const lower = message.toLowerCase();
3178
+ return CHUNK_ERROR_PATTERNS.some((pattern) => lower.includes(pattern));
3179
+ }
3180
+ function chunkLoadError(cause) {
3181
+ const error = /* @__PURE__ */ new Error("This app was updated while the tab was open, so part of it could not be loaded. Reload to continue.");
3182
+ Object.assign(error, {
3183
+ [CHUNK_LOAD_ERROR_FLAG]: true,
3184
+ cause
3185
+ });
3186
+ return error;
3187
+ }
3188
+ /**
3189
+ * Run a dynamic import, retrying once before declaring the chunk unreachable.
3190
+ *
3191
+ * Errors that are not chunk load failures — the imported module throwing while
3192
+ * it evaluates, say — are re-thrown untouched and never retried: running a
3193
+ * module's side effects twice is worse than the original failure.
3194
+ */
3195
+ async function loadChunk(loader) {
3196
+ try {
3197
+ return await loader();
3198
+ } catch (error) {
3199
+ if (!isChunkLoadError(error)) throw error;
3200
+ await new Promise((resolve) => setTimeout(resolve, 250));
3201
+ try {
3202
+ return await loader();
3203
+ } catch (retryError) {
3204
+ throw chunkLoadError(retryError);
3205
+ }
3206
+ }
3207
+ }
3208
+ /**
3209
+ * `React.lazy` with the retry above. A drop-in replacement — use it for every
3210
+ * lazy route or dialog, since any one of them can be the first chunk a stale
3211
+ * tab reaches for.
3212
+ *
3213
+ * Note that React caches the rejection: once a lazy component has failed, later
3214
+ * renders re-throw without calling the loader again. Resetting an error boundary
3215
+ * therefore cannot recover it, which is why the boundary offers a reload.
3216
+ */
3217
+ function lazyChunk(loader) {
3218
+ return React.lazy(() => loadChunk(loader));
3219
+ }
3220
+ //#endregion
3129
3221
  //#region src/components/ErrorBoundary.tsx
3130
3222
  /**
3223
+ * The one error a user can fix themselves. A deploy replaces the hashed chunk
3224
+ * files, so a tab opened before it cannot load any lazy view it has not already
3225
+ * fetched — with the browser's raw message ("Failed to fetch dynamically
3226
+ * imported module: …") this reads as a broken build rather than a stale tab.
3227
+ */
3228
+ var CHUNK_ERROR_DESCRIPTION = "This app was updated while the tab was open, so part of it could not be loaded. Reload to continue.";
3229
+ /**
3131
3230
  * Checks whether the error message relates to missing permissions or
3132
3231
  * authorization failures. Used to show a friendlier message in fullPage mode.
3133
3232
  */
@@ -3172,39 +3271,55 @@ var ErrorBoundary = class extends React.Component {
3172
3271
  return this.props.children;
3173
3272
  }
3174
3273
  renderInline() {
3274
+ const isStaleChunk = isChunkLoadError(this.state.error);
3175
3275
  return /* @__PURE__ */ jsxs("div", {
3176
- className: "flex flex-col m-2",
3177
- children: [/* @__PURE__ */ jsxs("div", {
3178
- className: "flex items-center m-2",
3179
- children: [/* @__PURE__ */ jsx(AlertCircleIcon$1, {
3180
- className: "text-red-500 dark:text-red-400",
3181
- size: iconSize.small
3182
- }), /* @__PURE__ */ jsx("div", {
3183
- className: "ml-4",
3184
- children: "Error"
3185
- })]
3186
- }), /* @__PURE__ */ jsx(Typography, {
3187
- variant: "caption",
3188
- children: this.state.error?.message ?? "See the error in the console"
3189
- })]
3276
+ className: "flex flex-col m-2 items-start",
3277
+ children: [
3278
+ /* @__PURE__ */ jsxs("div", {
3279
+ className: "flex items-center m-2",
3280
+ children: [isStaleChunk ? /* @__PURE__ */ jsx(RefreshCwIcon$1, {
3281
+ className: "text-text-secondary dark:text-text-secondary-dark",
3282
+ size: iconSize.small
3283
+ }) : /* @__PURE__ */ jsx(AlertCircleIcon$1, {
3284
+ className: "text-red-500 dark:text-red-400",
3285
+ size: iconSize.small
3286
+ }), /* @__PURE__ */ jsx("div", {
3287
+ className: "ml-4",
3288
+ children: isStaleChunk ? "New version available" : "Error"
3289
+ })]
3290
+ }),
3291
+ /* @__PURE__ */ jsx(Typography, {
3292
+ variant: "caption",
3293
+ children: isStaleChunk ? CHUNK_ERROR_DESCRIPTION : this.state.error?.message ?? "See the error in the console"
3294
+ }),
3295
+ isStaleChunk && /* @__PURE__ */ jsxs(Button, {
3296
+ variant: "outlined",
3297
+ color: "neutral",
3298
+ size: "small",
3299
+ className: "mt-3 ml-2",
3300
+ onClick: this.handleReload,
3301
+ children: [/* @__PURE__ */ jsx(RefreshCwIcon$1, { size: 16 }), "Reload"]
3302
+ })
3303
+ ]
3190
3304
  });
3191
3305
  }
3192
3306
  renderFullPage() {
3193
3307
  const { error, showDetails } = this.state;
3194
3308
  const isPermission = isPermissionError(error);
3195
- const Icon = isPermission ? ShieldAlertIcon : AlertCircleIcon$1;
3196
- const title = isPermission ? "Access denied" : "Something went wrong";
3197
- const description = isPermission ? "You don't have permission to access this resource. Please check your account permissions or contact your administrator." : "An unexpected error occurred. You can try reloading the page or going back.";
3309
+ const isStaleChunk = !isPermission && isChunkLoadError(error);
3310
+ const Icon = isPermission ? ShieldAlertIcon : isStaleChunk ? RefreshCwIcon$1 : AlertCircleIcon$1;
3311
+ const title = isPermission ? "Access denied" : isStaleChunk ? "New version available" : "Something went wrong";
3312
+ const description = isPermission ? "You don't have permission to access this resource. Please check your account permissions or contact your administrator." : isStaleChunk ? CHUNK_ERROR_DESCRIPTION : "An unexpected error occurred. You can try reloading the page or going back.";
3198
3313
  return /* @__PURE__ */ jsx("div", {
3199
3314
  className: cls("flex items-center justify-center min-h-[400px] h-full w-full", "bg-surface-50 dark:bg-surface-950"),
3200
3315
  children: /* @__PURE__ */ jsxs("div", {
3201
3316
  className: "flex flex-col items-center max-w-md px-6 py-10 text-center",
3202
3317
  children: [
3203
3318
  /* @__PURE__ */ jsx("div", {
3204
- className: cls("flex items-center justify-center w-14 h-14 rounded-xl mb-6", isPermission ? "bg-amber-100 dark:bg-amber-900/30" : "bg-red-100 dark:bg-red-900/30"),
3319
+ className: cls("flex items-center justify-center w-14 h-14 rounded-xl mb-6", isPermission ? "bg-amber-100 dark:bg-amber-900/30" : isStaleChunk ? "bg-surface-100 dark:bg-surface-800" : "bg-red-100 dark:bg-red-900/30"),
3205
3320
  children: /* @__PURE__ */ jsx(Icon, {
3206
3321
  size: 28,
3207
- className: isPermission ? "text-amber-600 dark:text-amber-400" : "text-red-500 dark:text-red-400"
3322
+ className: isPermission ? "text-amber-600 dark:text-amber-400" : isStaleChunk ? "text-text-secondary dark:text-text-secondary-dark" : "text-red-500 dark:text-red-400"
3208
3323
  })
3209
3324
  }),
3210
3325
  /* @__PURE__ */ jsx(Typography, {
@@ -3219,7 +3334,7 @@ var ErrorBoundary = class extends React.Component {
3219
3334
  }),
3220
3335
  /* @__PURE__ */ jsxs("div", {
3221
3336
  className: "flex gap-3",
3222
- children: [/* @__PURE__ */ jsxs(Button, {
3337
+ children: [!isStaleChunk && /* @__PURE__ */ jsxs(Button, {
3223
3338
  variant: "outlined",
3224
3339
  color: "neutral",
3225
3340
  size: "medium",
@@ -3233,7 +3348,7 @@ var ErrorBoundary = class extends React.Component {
3233
3348
  children: [/* @__PURE__ */ jsx(RefreshCwIcon$1, { size: 16 }), "Reload page"]
3234
3349
  })]
3235
3350
  }),
3236
- error?.message && /* @__PURE__ */ jsxs("div", {
3351
+ !isStaleChunk && error?.message && /* @__PURE__ */ jsxs("div", {
3237
3352
  className: "mt-8 w-full",
3238
3353
  children: [/* @__PURE__ */ jsxs("button", {
3239
3354
  onClick: this.toggleDetails,
@@ -8782,6 +8897,6 @@ function CollectionView({ dataController, properties, propertiesOrder, displayed
8782
8897
  });
8783
8898
  }
8784
8899
  //#endregion
8785
- export { Alert, AlertCircleIcon, AlertTriangleIcon, AlignLeftIcon, AppWindow, ArrowDownIcon, ArrowDownToLineIcon, ArrowLeftIcon, ArrowRightFromLineIcon, ArrowRightIcon, ArrowRightLeftIcon, ArrowRightToLineIcon, ArrowUpDownIcon, ArrowUpIcon, ArrowUpToLineIcon, Autocomplete, AutocompleteItem, Avatar, Badge, BoldIcon, BookOpenIcon, BooleanSwitch, BooleanSwitchWithLabel, Button, CHIP_COLORS, CHIP_HUES, CHIP_SEED_KEYS, CONTROL_HEIGHT, CalendarIcon, Card, CardView, CenteredView, CheckCircle2Icon, CheckCircleIcon, CheckIcon, CheckSquareIcon, Checkbox, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsLeftIcon, ChevronsRightIcon, ChevronsUpDownIcon, Chip, CircleDotIcon, CircleIcon, CircleUserIcon, CircularProgress, CircularProgressCenter, CodeIcon, Collapse, CollectionView, ColorPicker, ColumnsIcon, Container, CopyIcon, DatabaseIcon, DateTimeField, DebouncedTextField, Dialog, DialogActions, DialogContent, DialogTitle, DollarSignIcon, DownloadIcon, ErrorBoundary, ExpandablePanel, ExternalLinkIcon, EyeIcon, EyeOffIcon, FileIcon, FileSearchIcon, FileTextIcon, FileUpload, FilterChip, FilterIcon, FilterXIcon, FlagIcon, FolderIcon, FolderKanbanIcon, FolderPlusIcon, FolderUpIcon, FunctionSquareIcon, GitBranchIcon, GitHubIcon, GlobeIcon, HandleIcon, HashIcon, Heading1Icon, Heading2Icon, Heading3Icon, HelpCircleIcon, HistoryIcon, HomeIcon, IconButton, ImageIcon, ImageOffIcon, InfoIcon, InfoLabel, InputLabel, ItalicIcon, KanbanIcon, KanbanView, KeyIcon, KeyRoundIcon, Label, LanguagesIcon, LayoutGridIcon, Link2Icon, LinkIcon, ListIcon, ListOrderedIcon, ListPlusIcon, ListTodoIcon, ListView, LoaderIcon, LoadingButton, LockIcon, LogOutIcon, LucideIconByName, MailIcon, Markdown, Maximize2Icon, Menu, MenuIcon, MenuItem, Menubar, MenubarCheckboxItem, MenubarContent, MenubarItem, MenubarItemIndicator, MenubarMenu, MenubarPortal, MenubarRadioGroup, MenubarRadioItem, MenubarSeparator, MenubarShortcut, MenubarSub, MenubarSubContent, MenubarSubTrigger, MenubarSubTriggerIndicator, MenubarTrigger, MessageCircleIcon, MinusCircleIcon, MinusIcon, MoonIcon, MoreVerticalIcon, MultiSelect, MultiSelectContext, MultiSelectItem, Music2Icon, PanelLeftCloseIcon, PanelLeftIcon, PanelLeftOpenIcon, Paper, PauseIcon, PenLineIcon, PencilIcon, PhoneIcon, PinIcon, PlayIcon, PlusIcon, Popover, PopoverPrimitive, Portal, PortalContainerProvider, QuoteIcon, RadioGroup, RadioGroupItem, RefreshCcwIcon, RefreshCwIcon, RepeatIcon, ResizablePanels, Rows3Icon, SaveIcon, SearchBar, SearchIcon, Select, SelectGroup, SelectItem, SendIcon, Separator, SettingsIcon, Sheet, ShieldIcon, ShoppingCartIcon, Skeleton, Slider, SlidersHorizontalIcon, Slot, SquareIcon, StarIcon, StickyNoteIcon, StrikethroughIcon, SunIcon, SunMoonIcon, Tab, Table, TableBody, TableCell, TableHeader, TableIcon, TableRow, Tabs, TagIcon, TerminalIcon, TextField, TextIcon, TextareaAutosize, ToggleButtonGroup, Tooltip, Trash2Icon, TrendingUpIcon, TypeIcon, Typography, UnderlineIcon, UndoIcon, Unlink2Icon, UploadCloudIcon, UploadIcon, UserCheckIcon, UserIcon, UserPlus, UsersIcon, VideoIcon, VirtualTable, VirtualTableDateField, VirtualTableInput, VirtualTableNumberInput, VirtualTableSelect, VirtualTableSelectionProvider, VirtualTableSwitch, VoteIcon, Wand2Icon, WrenchIcon, XCircleIcon, XIcon, cardClickableMixin, cardMixin, cardSelectedMixin, cls, colorClassesMapping, controlHeightMixin, controlPaddingMixin, coolIconKeys, createVirtualTableSelectionStore, debounce, defaultBorderMixin, fieldBackgroundDisabledMixin, fieldBackgroundHoverMixin, fieldBackgroundInvisibleMixin, fieldBackgroundMixin, focusedClasses, focusedDisabled, focusedInvisibleMixin, getColorSchemeForKey, getColorSchemeForSeed, getLoadedLucideIcons, iconKeys, iconSize, loadLucideIcons, lucideIcons, paperMixin, resolveLucideIcon, useAutoComplete, useDebounceCallback, useDebounceValue, useDebouncedCallback, useInjectStyles, useLucideIcons, useOutsideAlerter, usePortalContainer, useVirtualTableCellSelected, useVirtualTableSelection };
8900
+ export { Alert, AlertCircleIcon, AlertTriangleIcon, AlignLeftIcon, AppWindow, ArrowDownIcon, ArrowDownToLineIcon, ArrowLeftIcon, ArrowRightFromLineIcon, ArrowRightIcon, ArrowRightLeftIcon, ArrowRightToLineIcon, ArrowUpDownIcon, ArrowUpIcon, ArrowUpToLineIcon, Autocomplete, AutocompleteItem, Avatar, Badge, BoldIcon, BookOpenIcon, BooleanSwitch, BooleanSwitchWithLabel, Button, CHIP_COLORS, CHIP_HUES, CHIP_SEED_KEYS, CONTROL_HEIGHT, CalendarIcon, Card, CardView, CenteredView, CheckCircle2Icon, CheckCircleIcon, CheckIcon, CheckSquareIcon, Checkbox, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsLeftIcon, ChevronsRightIcon, ChevronsUpDownIcon, Chip, CircleDotIcon, CircleIcon, CircleUserIcon, CircularProgress, CircularProgressCenter, CodeIcon, Collapse, CollectionView, ColorPicker, ColumnsIcon, Container, CopyIcon, DatabaseIcon, DateTimeField, DebouncedTextField, Dialog, DialogActions, DialogContent, DialogTitle, DollarSignIcon, DownloadIcon, ErrorBoundary, ExpandablePanel, ExternalLinkIcon, EyeIcon, EyeOffIcon, FileIcon, FileSearchIcon, FileTextIcon, FileUpload, FilterChip, FilterIcon, FilterXIcon, FlagIcon, FolderIcon, FolderKanbanIcon, FolderPlusIcon, FolderUpIcon, FunctionSquareIcon, GitBranchIcon, GitHubIcon, GlobeIcon, HandleIcon, HashIcon, Heading1Icon, Heading2Icon, Heading3Icon, HelpCircleIcon, HistoryIcon, HomeIcon, IconButton, ImageIcon, ImageOffIcon, InfoIcon, InfoLabel, InputLabel, ItalicIcon, KanbanIcon, KanbanView, KeyIcon, KeyRoundIcon, Label, LanguagesIcon, LayoutGridIcon, Link2Icon, LinkIcon, ListIcon, ListOrderedIcon, ListPlusIcon, ListTodoIcon, ListView, LoaderIcon, LoadingButton, LockIcon, LogOutIcon, LucideIconByName, MailIcon, Markdown, Maximize2Icon, Menu, MenuIcon, MenuItem, Menubar, MenubarCheckboxItem, MenubarContent, MenubarItem, MenubarItemIndicator, MenubarMenu, MenubarPortal, MenubarRadioGroup, MenubarRadioItem, MenubarSeparator, MenubarShortcut, MenubarSub, MenubarSubContent, MenubarSubTrigger, MenubarSubTriggerIndicator, MenubarTrigger, MessageCircleIcon, MinusCircleIcon, MinusIcon, MoonIcon, MoreVerticalIcon, MultiSelect, MultiSelectContext, MultiSelectItem, Music2Icon, PanelLeftCloseIcon, PanelLeftIcon, PanelLeftOpenIcon, Paper, PauseIcon, PenLineIcon, PencilIcon, PhoneIcon, PinIcon, PlayIcon, PlusIcon, Popover, PopoverPrimitive, Portal, PortalContainerProvider, QuoteIcon, RadioGroup, RadioGroupItem, RefreshCcwIcon, RefreshCwIcon, RepeatIcon, ResizablePanels, Rows3Icon, SaveIcon, SearchBar, SearchIcon, Select, SelectGroup, SelectItem, SendIcon, Separator, SettingsIcon, Sheet, ShieldIcon, ShoppingCartIcon, Skeleton, Slider, SlidersHorizontalIcon, Slot, SquareIcon, StarIcon, StickyNoteIcon, StrikethroughIcon, SunIcon, SunMoonIcon, Tab, Table, TableBody, TableCell, TableHeader, TableIcon, TableRow, Tabs, TagIcon, TerminalIcon, TextField, TextIcon, TextareaAutosize, ToggleButtonGroup, Tooltip, Trash2Icon, TrendingUpIcon, TypeIcon, Typography, UnderlineIcon, UndoIcon, Unlink2Icon, UploadCloudIcon, UploadIcon, UserCheckIcon, UserIcon, UserPlus, UsersIcon, VideoIcon, VirtualTable, VirtualTableDateField, VirtualTableInput, VirtualTableNumberInput, VirtualTableSelect, VirtualTableSelectionProvider, VirtualTableSwitch, VoteIcon, Wand2Icon, WrenchIcon, XCircleIcon, XIcon, cardClickableMixin, cardMixin, cardSelectedMixin, cls, colorClassesMapping, controlHeightMixin, controlPaddingMixin, coolIconKeys, createVirtualTableSelectionStore, debounce, defaultBorderMixin, fieldBackgroundDisabledMixin, fieldBackgroundHoverMixin, fieldBackgroundInvisibleMixin, fieldBackgroundMixin, focusedClasses, focusedDisabled, focusedInvisibleMixin, getColorSchemeForKey, getColorSchemeForSeed, getLoadedLucideIcons, iconKeys, iconSize, isChunkLoadError, lazyChunk, loadChunk, loadLucideIcons, lucideIcons, paperMixin, resolveLucideIcon, useAutoComplete, useDebounceCallback, useDebounceValue, useDebouncedCallback, useInjectStyles, useLucideIcons, useOutsideAlerter, usePortalContainer, useVirtualTableCellSelected, useVirtualTableSelection };
8786
8901
 
8787
8902
  //# sourceMappingURL=index.es.js.map