fix: quote slice IDs in generated slice index files when necessary - #259
Open
angeloashmore wants to merge 1 commit into
Open
fix: quote slice IDs in generated slice index files when necessary#259angeloashmore wants to merge 1 commit into
angeloashmore wants to merge 1 commit into
Conversation
The generated components map wrote slice IDs as bare object keys. An ID that is not a valid JavaScript identifier (for example, an ID with a dash) made the file invalid. The API accepts such IDs, so a pull can deliver them. Now the generator quotes an ID when it is not a valid identifier. Valid IDs stay bare, so formatters do not change the output. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
angeloashmore
added a commit
that referenced
this pull request
Aug 14, 2026
The eval used a snake_case slice ID to work around unquoted keys in the generated index file. PR #259 quotes IDs that are not valid identifiers, so the standard test slice works. Run the eval only after this branch includes that fix. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
angeloashmore
marked this pull request as ready for review
August 14, 2026 02:25
lihbr
approved these changes
Aug 14, 2026
lihbr
left a comment
Member
There was a problem hiding this comment.
Very minor suggestion, looks good otherwise :)
Comment on lines
+37
to
+44
| it("quotes the slice ID in the slice index file", async ({ expect, prismic, project }) => { | ||
| const { id, name } = buildSlice(); | ||
|
|
||
| const { stderr, exitCode } = await prismic("slice", ["create", name, "--id", id]); | ||
| expect(exitCode, stderr).toBe(0); | ||
|
|
||
| await expect(project).toHaveFile("slices/index.js", { contains: `"${id}": ${name}` }); | ||
| }); |
Member
There was a problem hiding this comment.
✨ #suggestion: I find it a bit hard to link here that the slice ID coming from buildSlice has to be quoted. Essentially, this test breaks if we change buildSlice's ID to sliceS${id} (hypen removed)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves:
Description
The generated slice index file writes slice IDs as bare object keys. An ID that is not a valid JavaScript identifier (e.g.
my-slice) makes the whole file invalid JavaScript. The API accepts such IDs, so aprismic pullcan deliver them and break a project's build.Checklist
Preview
A generated index file with a normal ID (
hero) and an ID that is not a valid identifier (legacy-hero):Before this PR, the
legacy-heroentry was written aslegacy-hero: LegacyHero, which is a syntax error.How to QA 1
prismic slice create MySlice --id my-slice."my-slice": MySliceand that the file is valid JavaScript.🤖 Generated with Claude Code
Note
Low Risk
Scoped to CLI code generation and tests; valid identifier IDs behave as before with no runtime auth or data-path changes.
Overview
Generated slice library index files now emit valid JavaScript object keys for slice IDs that are not legal identifiers (e.g. hyphenated IDs like
legacy-hero).A shared
formatObjectKeyhelper leaves normal identifiers unquoted and usesJSON.stringifyfor everything else. Next.js, Nuxt, and SvelteKit adapters use it when building thecomponentsmap increateSliceIndexFile.Test support was updated so slice-index assertions accept quoted keys, and a slice create test checks that non-identifier IDs appear quoted in
slices/index.js.Reviewed by Cursor Bugbot for commit 18330d7. Bugbot is set up for automated code reviews on this repo. Configure here.
Footnotes
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩