@reticlehq/next 3.10.3 → 3.10.4

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.
Files changed (2) hide show
  1. package/index.cjs +57 -0
  2. package/package.json +2 -2
package/index.cjs CHANGED
@@ -525,6 +525,55 @@ function sdkPackageVersion() {
525
525
  return '';
526
526
  }
527
527
 
528
+ /**
529
+ * The state folder as a RegExp: the form webpack accepts alone, and the form Next's own default uses.
530
+ *
531
+ * Anchored on the start of the path or a separator, so it matches the folder and not a name that
532
+ * only ends in `.reticle`. Both separators are accepted because the path arrives in the platform's
533
+ * own form.
534
+ */
535
+ const STATE_DIR_IGNORE = new RegExp(
536
+ `(^|[\\\\/])${RETICLE_HOME_DIR.replace('.', '\\.')}([\\\\/]|$)`,
537
+ );
538
+ /** The same folder as a glob, for the one case where webpack takes only strings (an array of them). */
539
+ const STATE_DIR_IGNORE_GLOB = `**/${RETICLE_HOME_DIR}/**`;
540
+
541
+ /**
542
+ * Add the Reticle state folder to webpack's `watchOptions.ignored`, and keep what is already there.
543
+ *
544
+ * The daemon rewrites files in `<project>/.reticle/` while a tab is connected (`ambient.json`, and
545
+ * the session journals). Next's default ignore list holds only `.git`, `.next` and `node_modules`,
546
+ * so every write looked like a source change. The dev server then sent a server-component update
547
+ * every few seconds, and the page refetched and lost its refs and sessions.
548
+ *
549
+ * `ignored` has three legal shapes in webpack 5, and the merge must not treat them alike:
550
+ * - A RegExp (the shape Next sets): join it with ours in one RegExp. An array may hold only
551
+ * strings, so the RegExp cannot go in a list.
552
+ * - A string: it is one glob. Spreading it would split it into one pattern per character, which
553
+ * drops the app's own exclusion with no error.
554
+ * - An array of strings: append the glob. An empty string is invalid in this list, so skip it.
555
+ *
556
+ * It returns a new value and never changes the one it is given: Next freezes its own options.
557
+ *
558
+ * @param {unknown} existing
559
+ * @returns {RegExp | string[]}
560
+ */
561
+ function mergeWatchIgnored(existing) {
562
+ if (existing === undefined || existing === null) {
563
+ return STATE_DIR_IGNORE;
564
+ }
565
+ if (existing instanceof RegExp) {
566
+ // `g` and `y` make `.test()` remember the last match, so a joined pattern would skip paths.
567
+ const flags = existing.flags.replace(/[gy]/g, '');
568
+ return new RegExp(`(?:${existing.source})|(?:${STATE_DIR_IGNORE.source})`, flags);
569
+ }
570
+ const listed = Array.isArray(existing) ? existing : [existing];
571
+ return [
572
+ ...listed.filter((entry) => typeof entry === 'string' && entry !== ''),
573
+ STATE_DIR_IGNORE_GLOB,
574
+ ];
575
+ }
576
+
528
577
  /**
529
578
  * @param {import('next').NextConfig} [nextConfig]
530
579
  * @param {{ sourceMapping?: boolean }} [options] Pass `{ sourceMapping: false }` for an app that
@@ -611,6 +660,14 @@ function withReticle(nextConfig = {}, options = {}) {
611
660
  NEXT_PUBLIC_RETICLE_SDK_VERSION: sdkPackageVersion(),
612
661
  },
613
662
  webpack(config, ctx) {
663
+ if (ctx?.dev) {
664
+ // A new object, not an edit: Next hands over `watchOptions` frozen. This is separate from
665
+ // source mapping on purpose, so `sourceMapping: false` still stops the rebuild loop.
666
+ config.watchOptions = {
667
+ ...config.watchOptions,
668
+ ignored: mergeWatchIgnored(config.watchOptions?.ignored),
669
+ };
670
+ }
614
671
  if (options.sourceMapping !== false) {
615
672
  config.module = config.module || { rules: [] };
616
673
  config.module.rules = config.module.rules || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reticlehq/next",
3
- "version": "3.10.3",
3
+ "version": "3.10.4",
4
4
  "description": "Next.js helper for Reticle: keeps SWC, adds source-file mapping via a dev-only webpack pre-loader (data-reticle-source).",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Reticle contributors",
@@ -38,7 +38,7 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@babel/core": "^7.26.0",
41
- "@reticlehq/babel-plugin": "3.10.3"
41
+ "@reticlehq/babel-plugin": "3.10.4"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "next": ">=13"