-
Notifications
You must be signed in to change notification settings - Fork 1
Bugfix: Uncaught error on adding new content block #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…or: undefined is not valid JSON error
|
Preview deployment: https://bugfixxcontent-block-uncaught-error.preview.avy-fx.org |
…mn default values + migration acceptance explanation
Migration Safety CheckFound 20 potential issues: 20251024_203935_content_block_default_value.ts Warning (line 11): ALTER keyword detected - review for data loss `ALTER TABLE \`home_pages_blocks_content_columns\` ADD COLUMN \`__new_rich_text\` text DEFAULT '${DEFAULT_LEXICAL_VALUE}';`,Warning (line 19): DROP keyword detected - review for data loss await db.run(sql`ALTER TABLE \`home_pages_blocks_content_columns\` DROP COLUMN \`rich_text\`;`)Warning (line 19): ALTER keyword detected - review for data loss await db.run(sql`ALTER TABLE \`home_pages_blocks_content_columns\` DROP COLUMN \`rich_text\`;`)Warning (line 21): ALTER keyword detected - review for data loss sql`ALTER TABLE \`home_pages_blocks_content_columns\` RENAME COLUMN \`__new_rich_text\` TO \`rich_text\`;`,Warning (line 21): RENAME keyword detected - review for data loss sql`ALTER TABLE \`home_pages_blocks_content_columns\` RENAME COLUMN \`__new_rich_text\` TO \`rich_text\`;`,Warning (line 27): ALTER keyword detected - review for data loss `ALTER TABLE \`_home_pages_v_blocks_content_columns\` ADD COLUMN \`__new_rich_text\` text DEFAULT '${DEFAULT_LEXICAL_VALUE}';`,Warning (line 35): DROP keyword detected - review for data loss await db.run(sql`ALTER TABLE \`_home_pages_v_blocks_content_columns\` DROP COLUMN \`rich_text\`;`)Warning (line 35): ALTER keyword detected - review for data loss await db.run(sql`ALTER TABLE \`_home_pages_v_blocks_content_columns\` DROP COLUMN \`rich_text\`;`)Warning (line 37): ALTER keyword detected - review for data loss sql`ALTER TABLE \`_home_pages_v_blocks_content_columns\` RENAME COLUMN \`__new_rich_text\` TO \`rich_text\`;`,Warning (line 37): RENAME keyword detected - review for data loss sql`ALTER TABLE \`_home_pages_v_blocks_content_columns\` RENAME COLUMN \`__new_rich_text\` TO \`rich_text\`;`,Warning (line 43): ALTER keyword detected - review for data loss `ALTER TABLE \`pages_blocks_content_columns\` ADD COLUMN \`__new_rich_text\` text DEFAULT '${DEFAULT_LEXICAL_VALUE}';`,Warning (line 51): DROP keyword detected - review for data loss await db.run(sql`ALTER TABLE \`pages_blocks_content_columns\` DROP COLUMN \`rich_text\`;`)Warning (line 51): ALTER keyword detected - review for data loss await db.run(sql`ALTER TABLE \`pages_blocks_content_columns\` DROP COLUMN \`rich_text\`;`)Warning (line 53): ALTER keyword detected - review for data loss sql`ALTER TABLE \`pages_blocks_content_columns\` RENAME COLUMN \`__new_rich_text\` TO \`rich_text\`;`,Warning (line 53): RENAME keyword detected - review for data loss sql`ALTER TABLE \`pages_blocks_content_columns\` RENAME COLUMN \`__new_rich_text\` TO \`rich_text\`;`,Warning (line 59): ALTER keyword detected - review for data loss `ALTER TABLE \`_pages_v_blocks_content_columns\` ADD COLUMN \`__new_rich_text\` text DEFAULT '${DEFAULT_LEXICAL_VALUE}';`,Warning (line 67): DROP keyword detected - review for data loss await db.run(sql`ALTER TABLE \`_pages_v_blocks_content_columns\` DROP COLUMN \`rich_text\`;`)Warning (line 67): ALTER keyword detected - review for data loss await db.run(sql`ALTER TABLE \`_pages_v_blocks_content_columns\` DROP COLUMN \`rich_text\`;`)Warning (line 69): ALTER keyword detected - review for data loss sql`ALTER TABLE \`_pages_v_blocks_content_columns\` RENAME COLUMN \`__new_rich_text\` TO \`rich_text\`;`,Warning (line 69): RENAME keyword detected - review for data loss sql`ALTER TABLE \`_pages_v_blocks_content_columns\` RENAME COLUMN \`__new_rich_text\` TO \`rich_text\`;`,Review these patterns and add backup/restore logic if needed. See |
…he same pattern for tables
… a UI field component to handle adding a default column
… the updated default value JSON
Description
The same or similar problem reported here: payloadcms/payload#14022
The underlying issue seems to be have been fixed in v3.60.0: payloadcms/payload#13813
This PR uses the fix suggested from payloadcms/payload#14022 which adds a valid lexical node definition as the default value for the field. We also include a default column.
Related Issues
Fixes #608
Key Changes
Migration explanation
See
src/migrations/20251024_203935_content_block_default_value_explanation.mdfor full explanation.This PR includes a migration that uses the table recreation pattern that can result in data loss. I ran this locally and we don't experience data loss from this because these tables do not have any child foreign key relationships. So dropping these tables doesn't result in any cascade deletes.This migration uses a column recreation pattern instead of the table recreation pattern.
I would love for reviewers to validate that logic before we merge this. Even though I did test this locally and it logically makes sense to me I want to make sure I'm not missing something.