Skip to content

Commit b234f1d

Browse files
committed
fix: Only register guids from blocks that are valid.
1 parent 7d0c28d commit b234f1d

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

packages/@css-blocks/core/src/BlockParser/BlockFactory.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,18 @@ export class BlockFactory {
220220
block.setName(uniqueName);
221221
}
222222

223-
// Ensure the GUID is unique.
224-
const guidRegResult = this.registerGuid(block.guid);
225-
if (!guidRegResult) {
226-
block.addError(
227-
new CssBlockError("Block uses a GUID that has already been used! Check dependencies for conflicting GUIDs and/or increase the number of significant characters used to generate GUIDs.", {
228-
filename: block.identifier,
229-
},
230-
),
231-
);
223+
// We only register guids from blocks that don't have errors because those will get re-parsed.
224+
if (block.isValid()) {
225+
// Ensure the GUID is unique.
226+
const guidRegResult = this.registerGuid(block.guid);
227+
if (!guidRegResult) {
228+
block.addError(
229+
new CssBlockError("Block uses a GUID that has already been used! Check dependencies for conflicting GUIDs and/or increase the number of significant characters used to generate GUIDs.", {
230+
filename: block.identifier,
231+
},
232+
),
233+
);
234+
}
232235
}
233236

234237
// if the block has any errors, surface them here unless we're in fault tolerant mode.

packages/@css-blocks/core/src/BlockTree/Block.ts

+4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ export class Block
233233
this._blockErrors.push(error);
234234
}
235235

236+
isValid(): boolean {
237+
return this._blockErrors.length === 0;
238+
}
239+
236240
/**
237241
* Checks for errors on the block
238242
* @returns true if the block is valid else throws the errors on the block

0 commit comments

Comments
 (0)