next-intl 4.5.7 → 4.5.8

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.
@@ -14,43 +14,61 @@ class SaveScheduler {
14
14
  resolve,
15
15
  reject
16
16
  });
17
- if (this.pendingResolvers.length === 1 && !this.isSaving) {
18
- // No pending saves and not currently saving, save immediately
19
- this.executeSave(saveTask);
20
- } else if (this.pendingResolvers.length > 1) {
21
- // Multiple pending saves, schedule/reschedule save
22
- this.scheduleSave(saveTask);
17
+ this.nextSaveTask = saveTask;
18
+ if (!this.isSaving && !this.saveTimeout) {
19
+ // Not currently saving and no scheduled save, save immediately
20
+ this.executeSave();
21
+ } else if (this.saveTimeout) {
22
+ // A save is already scheduled, reschedule to debounce
23
+ this.scheduleSave();
23
24
  }
25
+ // If isSaving is true and no timeout is scheduled, the current save
26
+ // will check for pending resolvers when it completes and schedule
27
+ // another save if needed (see finally block in executeSave)
24
28
  });
25
29
  }
26
- scheduleSave(saveTask) {
30
+ scheduleSave() {
27
31
  if (this.saveTimeout) {
28
32
  clearTimeout(this.saveTimeout);
29
33
  }
30
34
  this.saveTimeout = setTimeout(() => {
31
- this.executeSave(saveTask);
35
+ this.saveTimeout = undefined;
36
+ this.executeSave();
32
37
  }, this.delayMs);
33
38
  }
34
- async executeSave(saveTask) {
39
+ async executeSave() {
35
40
  if (this.isSaving) {
36
41
  return;
37
42
  }
43
+ const saveTask = this.nextSaveTask;
44
+ if (!saveTask) {
45
+ return;
46
+ }
47
+
48
+ // Capture current pending resolvers for this save
49
+ const resolversForThisSave = this.pendingResolvers;
50
+ this.pendingResolvers = [];
51
+ this.nextSaveTask = undefined;
38
52
  this.isSaving = true;
39
53
  try {
40
54
  const result = await saveTask();
41
55
 
42
- // Resolve all pending promises with the same result
43
- this.pendingResolvers.forEach(({
56
+ // Resolve only the promises that were pending when this save started
57
+ resolversForThisSave.forEach(({
44
58
  resolve
45
59
  }) => resolve(result));
46
60
  } catch (error) {
47
- // Reject all pending promises with the same error
48
- this.pendingResolvers.forEach(({
61
+ // Reject only the promises that were pending when this save started
62
+ resolversForThisSave.forEach(({
49
63
  reject
50
64
  }) => reject(error));
51
65
  } finally {
52
- this.pendingResolvers = [];
53
66
  this.isSaving = false;
67
+
68
+ // If new saves were requested during this save, schedule another
69
+ if (this.pendingResolvers.length > 0) {
70
+ this.scheduleSave();
71
+ }
54
72
  }
55
73
  }
56
74
  destroy() {
@@ -59,6 +77,7 @@ class SaveScheduler {
59
77
  this.saveTimeout = undefined;
60
78
  }
61
79
  this.pendingResolvers = [];
80
+ this.nextSaveTask = undefined;
62
81
  this.isSaving = false;
63
82
  }
64
83
  }
@@ -21,7 +21,7 @@ class JSONFormatter extends Formatter {
21
21
  for (const message of getSortedMessages(messages)) {
22
22
  setNestedProperty(root, message.id, message.message);
23
23
  }
24
- return JSON.stringify(root, null, 2);
24
+ return JSON.stringify(root, null, 2) + '\n';
25
25
  }
26
26
  toJSONString(source) {
27
27
  return source;
@@ -1 +1 @@
1
- class e{isSaving=!1;pendingResolvers=[];constructor(e=50){this.delayMs=e}async schedule(e){return new Promise(((s,i)=>{this.pendingResolvers.push({resolve:s,reject:i}),1!==this.pendingResolvers.length||this.isSaving?this.pendingResolvers.length>1&&this.scheduleSave(e):this.executeSave(e)}))}scheduleSave(e){this.saveTimeout&&clearTimeout(this.saveTimeout),this.saveTimeout=setTimeout((()=>{this.executeSave(e)}),this.delayMs)}async executeSave(e){if(!this.isSaving){this.isSaving=!0;try{const s=await e();this.pendingResolvers.forEach((({resolve:e})=>e(s)))}catch(e){this.pendingResolvers.forEach((({reject:s})=>s(e)))}finally{this.pendingResolvers=[],this.isSaving=!1}}}destroy(){this.saveTimeout&&(clearTimeout(this.saveTimeout),this.saveTimeout=void 0),this.pendingResolvers=[],this.isSaving=!1}}export{e as default};
1
+ class e{isSaving=!1;pendingResolvers=[];constructor(e=50){this.delayMs=e}async schedule(e){return new Promise(((s,i)=>{this.pendingResolvers.push({resolve:s,reject:i}),this.nextSaveTask=e,this.isSaving||this.saveTimeout?this.saveTimeout&&this.scheduleSave():this.executeSave()}))}scheduleSave(){this.saveTimeout&&clearTimeout(this.saveTimeout),this.saveTimeout=setTimeout((()=>{this.saveTimeout=void 0,this.executeSave()}),this.delayMs)}async executeSave(){if(this.isSaving)return;const e=this.nextSaveTask;if(!e)return;const s=this.pendingResolvers;this.pendingResolvers=[],this.nextSaveTask=void 0,this.isSaving=!0;try{const i=await e();s.forEach((({resolve:e})=>e(i)))}catch(e){s.forEach((({reject:s})=>s(e)))}finally{this.isSaving=!1,this.pendingResolvers.length>0&&this.scheduleSave()}}destroy(){this.saveTimeout&&(clearTimeout(this.saveTimeout),this.saveTimeout=void 0),this.pendingResolvers=[],this.nextSaveTask=void 0,this.isSaving=!1}}export{e as default};
@@ -1 +1 @@
1
- import{setNestedProperty as s}from"../utils.js";import e from"./Formatter.js";import{getSortedMessages as t}from"./utils.js";class r extends e{static NAMESPACE_SEPARATOR=".";EXTENSION=".json";parse(s){const e=JSON.parse(s),t=[];return this.traverseMessages(e,((s,e)=>{t.push({id:e,message:s})})),t}serialize(e){const r={};for(const o of t(e))s(r,o.id,o.message);return JSON.stringify(r,null,2)}toJSONString(s){return s}traverseMessages(s,e,t=""){for(const o of Object.keys(s)){const a=t?t+r.NAMESPACE_SEPARATOR+o:o,i=s[o];"string"==typeof i?e(i,a):"object"==typeof i&&this.traverseMessages(i,e,a)}}}export{r as default};
1
+ import{setNestedProperty as s}from"../utils.js";import e from"./Formatter.js";import{getSortedMessages as t}from"./utils.js";class r extends e{static NAMESPACE_SEPARATOR=".";EXTENSION=".json";parse(s){const e=JSON.parse(s),t=[];return this.traverseMessages(e,((s,e)=>{t.push({id:e,message:s})})),t}serialize(e){const r={};for(const o of t(e))s(r,o.id,o.message);return JSON.stringify(r,null,2)+"\n"}toJSONString(s){return s}traverseMessages(s,e,t=""){for(const o of Object.keys(s)){const a=t?t+r.NAMESPACE_SEPARATOR+o:o,i=s[o];"string"==typeof i?e(i,a):"object"==typeof i&&this.traverseMessages(i,e,a)}}}export{r as default};
@@ -8,6 +8,7 @@ export default class SaveScheduler<Value> {
8
8
  private isSaving;
9
9
  private delayMs;
10
10
  private pendingResolvers;
11
+ private nextSaveTask?;
11
12
  constructor(delayMs?: number);
12
13
  schedule(saveTask: SaveTask<Value>): Promise<Value>;
13
14
  private scheduleSave;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "4.5.7",
3
+ "version": "4.5.8",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -127,9 +127,9 @@
127
127
  "@formatjs/intl-localematcher": "^0.5.4",
128
128
  "@swc/core": "^1.15.2",
129
129
  "negotiator": "^1.0.0",
130
- "next-intl-swc-plugin-extractor": "^4.5.7",
130
+ "next-intl-swc-plugin-extractor": "^4.5.8",
131
131
  "po-parser": "^1.0.2",
132
- "use-intl": "^4.5.7"
132
+ "use-intl": "^4.5.8"
133
133
  },
134
134
  "peerDependencies": {
135
135
  "next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
@@ -141,5 +141,5 @@
141
141
  "optional": true
142
142
  }
143
143
  },
144
- "gitHead": "2ccc147b68227b32ea451935718c3eb5e73d6e2f"
144
+ "gitHead": "a0e97c1c84f7bb787ec3397fcd79a6dfe9a9bbd1"
145
145
  }