Skip to content

Do not add default metadata to cells when opening the Property Inspector - #20160

Merged
krassowski merged 19 commits into
jupyterlab:mainfrom
b84330808:metadata-form-no-default-writes
Oct 30, 2026
Merged

krassowski merged 19 commits into
jupyterlab:mainfrom
b84330808:metadata-form-no-default-writes

Conversation

@b84330808

@b84330808 b84330808 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

References

Fixes #17562.

#20002 also changes MetadataFormWidget.updateMetadata, for #19995 (a form writing to a cell it was not built for). This pull request also stops the write captured in #19995, because the form no longer writes the values that it fills in when it is created. #20002 is still needed for edits in a form built for another cell and for custom fields. One of them will need a merge after the other.

Code changes

When the form is built, react-jsonschema-form fills in the schema defaults and calls onChange with them, and the form wrote every one of them to the cell. Changing one field later also wrote the defaults of all the other fields.

The form now writes only the metadata key whose field was changed. The field of each metadata key (each property of the root field) wraps RJSF's SchemaField and passes on every change with its key as the id. onChange writes only that key, with its whole value. Values that the form fills in by itself come without an id, so they are not written. The key comes from the field's name rather than from the id that RJSF gives the field, because ids join nested names with _ and keys may contain _ too. IFormComponentProps.onChange now declares the id argument that RJSF already passes.

The form also loads the current values of conditional keys, so it no longer shows their defaults over existing values. A nested key whose parent is not an object made the form throw, for example /slideshow/slide_type with "slideshow": null. Loading the conditional keys also made the form throw for the keys of an inactive branch, such as /options/enabled with "options": false. The form now treats such a parent as missing when it loads the metadata, replaces it with an object when it writes the nested key, and keeps it when it removes the nested key. updateMetadata() still writes a value that the user changes back to its default, unless writeDefault is false. The galata tests that expected defaults right after the form opens now expect them to be missing.

@dturaev wrote the tests for conditional schemas and the commits f509456, 9631fba, 93f15be, 17e385b, a339e0e and 74c6522. 93f15be replaced the earlier comparison with the filled-in defaults by the field-key tracking above.

User-facing changes

Expanding Common Tools in the Property Inspector, or changing one field in it, no longer adds editable: true, deletable: true, slideshow: {"slide_type": ""}, tags: [] or other default values to the cell metadata.

I tested this change in the browser.

Choosing Slide as the Slide Type in Common Tools for a cell whose metadata has "slideshow": null now sets "slideshow": {"slide_type": "slide"}. In 4.6.4 it emptied the Common Tools section and left the metadata unchanged.

Backwards-incompatible changes

None.

AI usage

  • YES: Some or all of the content of this PR was generated by AI.
  • YES: The human author has carefully reviewed this PR and run this code (keep this PR "draft" until the answer is YES)
  • AI tools and models used: Claude Code with Claude Opus 5.5, at xhigh effort. @dturaev's follow-up commits were made with Claude Opus 5.5 and tested with the help of Codex; I don't know the effort levels of those. @krassowski's - Opus 5.5.

b84330808 and others added 2 commits October 20, 2026 02:11
The form fills in the schema defaults when it is built and passes them to
updateMetadata, which added them to the cell metadata.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jupyterlab-probot

jupyterlab-probot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

View the integration tests report in the browser: UI tests report

@b84330808

Copy link
Copy Markdown
Contributor Author

@meeseeksdev tag bug

@dturaev

dturaev commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

I submitted issue #19995, and I'd really like to help fix JupyterLab's metadata behavior, so with assistance from Codex (GPT-6 Astra), I tested 05ebf0b locally. All 14 existing metadataform tests passed. I also combined it with #20002 (f0dd6b4); all 18 existing tests, including the stale-form/unmount regressions, passed.

The additional tests found a conditional-schema issue in _getDefault: it scans both then and else without resolving which branch is active.

For example, suppose the inactive then branch gives /choice a default of "then-default", while the active else branch allows that value but has no default. With choice initially absent, an explicit updateMetadata call selecting "then-default" is silently ignored because it matches the inactive branch's default. This fails on the PR and passes when the new filtering is removed.

There is also an initialization case: if the branches have different defaults and else is active, its default still gets written to the cell because the filter compares it with the then default.

Could the lookup use the schema resolved for the current form data, consistent with RJSF, rather than the first default found across branches?

Attached are four additional tests: two passing controls and the two failing cases above. They render real RJSF forms; the explicit-edit case calls updateMetadata directly after rendering, so these are component tests, not a full browser reproduction. The same two failures remain with #20002 applied. This concerns custom conditional forms; I haven't reproduced it in the standard Common Tools schema.

conditional-defaults-tests.patch.txt

b84330808 and others added 2 commits October 20, 2026 12:19
…lects

Evaluate each `if` with the form's validator, as the form does, instead of
taking the first default found in either branch. The validator loading
moves to a module shared by the form and the widget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@b84330808

Copy link
Copy Markdown
Contributor Author

Thank you for testing this, and for the tests. You're right: scanning both branches made an explicit value disappear when it matched the inactive branch's default, and the active else default could still get written.

_getDefault now evaluates each if with the form's validator against the submitted form data, the same check RJSF uses to pick the branch, and only uses the defaults of the selected branch. Before the validator has loaded, no conditional defaults are used, so those keys are written as before. Since the form and the widget now both need the validator, its lazy loading moved from form.tsx to a small internal validator.ts.

I added your four cases to metadataFormWidget.spec.ts (f654785, with you as co-author). The two you reported fail on that commit and pass with the fix in 32eb77e, and all 18 metadataform tests pass.

@krassowski krassowski added this to the 4.7.0 milestone Oct 20, 2026
@dturaev

dturaev commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

(Update: see the next comment for a simpler approach that replaces patch 2.)

Thanks for the update. With help from Claude and Codex, I re-tested 32eb77e with the metadataform Jest suite and in the browser, using dev mode and Playwright in headless Chromium.

Common Tools behaves as intended in the cases I tested: opening it and moving between code, markdown and raw cells without the relevant metadata does not add defaults or dirty the notebook. Existing slideshow and tags values are preserved, and changing a field writes only its corresponding metadata. On main, opening the tools adds the missing defaults, including raw_mimetype for raw cells.

The attached follow-up addresses two remaining problems.

1. Preserve existing values of conditional fields

_update() loads values only for top-level properties, omitting conditional keys. Consequently, opening the form replaces a stored conditional value with its default. With the first schema below, {"condition": false, "choice": "custom-value"} becomes {"condition": false, "choice": "else-default"}. This also occurs on main.

Patch 1 loads all metadataKeys. It also strengthens the existing reset test by asserting that custom-value survives form initialization, before the explicit update. Without that assertion, the test passes even though initialization has already overwritten the value.

2. Compare with the values RJSF actually fills in

During initialization, the form supplies the stored metadata to getDefaultFormState. RJSF computes defaults from that input, then resolves the displayed schema using the populated data. When the condition itself has an unstored default, these steps can select different branches:

  • With defaults in both branches, the checkbox is checked but Choice contains else-default. Opening the form currently saves that automatically populated value.
  • With no else default, the checkbox is checked but Choice is empty. Explicitly setting then-default is therefore a real edit and must survive reloading, even though it equals the displayed branch's schema default.

Patch 2 computes the initialization baseline with RJSF’s getDefaultFormState and skips a missing metadata value only when it matches what the form would fill in automatically. It also fixes partial updates from custom fields, which send only their own key. On 32eb77e, the condition is then evaluated as missing: on a cell with condition: true stored, setting the else default is dropped and setting the then default is saved. Patch 2 uses the stored condition, and interprets an unstored one through the same initialization behavior; it removes _getDefault() and isValid().

Remaining limitation: when switching the condition makes RJSF fill in a field that only the new branch has, that field’s default is saved. On 32eb77e, the same switch instead saves the old branch’s value that RJSF carries over; main saves both. Fixing this needs additional handling and regression coverage; this series doesn’t attempt it.

Validation and integration

Check 32eb77e With this series
Expanded metadataform suite: 24 tests 18 pass, 6 fail 24 pass
Combined with #20002, including its regressions — 28 pass

The six baseline failures are five added cases and the strengthened initialization assertion. The other added case provides passing coverage of an explicit edit.

The two commits apply to 32eb77e independently or together, in either order. Patch 2 adds @rjsf/utils, which @jupyterlab/ui-components already uses.

For #20002, the constructor conflict can be resolved by retaining both its _sourceCell capture and this PR's getValidator()/ensureValidator() calls. The integration also preserves #20002's current-form callback guard.

pr20160-follow-up.patch.txt

Forms used in the browser tests: Metadata Form user settings
{
  "metadataforms": [
    {
      "id": "conditionalTestSection",
      "label": "Conditional test",
      "metadataSchema": {
        "type": "object",
        "properties": {
          "/condition": { "title": "Condition", "type": "boolean" }
        },
        "allOf": [
          {
            "if": {
              "properties": { "/condition": { "const": true } },
              "required": ["/condition"]
            },
            "then": {
              "properties": {
                "/choice": {
                  "title": "Choice",
                  "type": "string",
                  "default": "then-default"
                }
              }
            },
            "else": {
              "properties": {
                "/choice": {
                  "title": "Choice",
                  "type": "string",
                  "default": "else-default"
                }
              }
            }
          }
        ]
      }
    },
    {
      "id": "conditionDefaultTestSection",
      "label": "Condition default test",
      "metadataSchema": {
        "type": "object",
        "properties": {
          "/cond2": {
            "title": "Condition 2",
            "type": "boolean",
            "default": true
          }
        },
        "allOf": [
          {
            "if": {
              "properties": { "/cond2": { "const": true } },
              "required": ["/cond2"]
            },
            "then": {
              "properties": {
                "/choice2": {
                  "title": "Choice 2",
                  "type": "string",
                  "default": "then-default"
                }
              }
            },
            "else": {
              "properties": {
                "/choice2": {
                  "title": "Choice 2",
                  "type": "string",
                  "default": "else-default"
                }
              }
            }
          }
        ]
      }
    }
  ]
}

For the empty-choice case, remove default from the second form's else choice definition.

dturaev and others added 2 commits October 20, 2026 23:57
The form data was built from the top-level properties only. The form
showed the default of a conditional key that has a value, and its first
change wrote that default over the value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UVgHJTXiavHWWyVC9dv2vF
Compare a value of missing metadata with the value that the form fills
in for it, computed from the current metadata with RJSF's
getDefaultFormState, instead of selecting the conditional branches
separately. RJSF selects the branch of the defaults with the metadata,
while it renders the branch that the filled-in data selects, so a
condition with a default made the two differ: opening the form wrote
the default of the other branch, and a value that the form does not
show was skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UVgHJTXiavHWWyVC9dv2vF
@b84330808

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the careful re-test and for the follow-up patches. I applied both commits as they are, keeping you as the author, and pushed them to this PR. With the new tests on the 32eb77e source I got the same six failures you listed.

Comparing with what getDefaultFormState actually fills in is a much better baseline than evaluating the if branches on our side, and it also covers the partial updates from custom fields, so I'm happy to drop _getDefault() and isValid(). @rjsf/utils resolves to the same 5.14.3 that @rjsf/core and @jupyterlab/ui-components already use, so it adds nothing new to the bundle.

One small thing: _getCurrentFormData() and _isShown() read the metadata and check the cell type the same way _update() does when it builds the form data. _update() could probably reuse them, but that can also be a follow-up.

I agree that the remaining case (switching the condition and saving the default of a field that only the new branch has) is better handled separately. Thanks also for the notes on combining this with #20002.

@b84330808
b84330808 marked this pull request as ready for review October 20, 2026 15:55
@dturaev

dturaev commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for adding the changes. Below is also a suggestion for an alternative approach, which may be the better long-term design. It writes only the metadata key of the field the user changed, instead of comparing with the values the form fills in.

@dturaev

dturaev commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Alternative to the fill comparison: explicit field-key tracking

The attached patch replaces the comparison with the filled values (9631fba) by tracking the metadata key of each change explicitly. Each property of the root field, i.e. each metadata key, records its key for each change that it passes on, and the form writes only that key. Defaults that the form fills in for other metadata keys (when the form is created, or for a branch that a change selects) are not written. A changed key is written with its whole value, e.g. an object including the defaults filled in it. updateMetadata() is unchanged from main.

The patch is also smaller. Compared with 9631fba, it removes 143 lines of source and adds 82: the fill comparison in metadataform.ts and validator.ts goes away, and the new code is in form.tsx. Over the whole PR, the source diff against the base becomes +111/−33 instead of +178/−39.

This is another implementation option. The Common Tools interactions tested produced the same visible behavior with either approach. Differences remain for custom conditional forms, explicit writes equal to a missing key's default, and stale initialization (discussed below). The trade-off is that this hooks into RJSF more deeply: a wrapper around its SchemaField, and it relies on the field id that RJSF passes to onChange. RJSF documents that id, but IFormComponentProps.onChange in ui-components declares only the event. If you take this version, adding id?: string there would make the dependency explicit. If you'd rather keep this PR as it is, I can open a separate PR for this after it's merged.

Known limitations of the fill comparison in 9631fba. If you keep the fill comparison, a short note on these in the PR description would help the maintainers:

Why not take the key from the field id: ids join names with _, so /a → b and a key /a_b have the same id. A reviewer found a case where this goes wrong: when checking a.b selects a branch that fills in /a_b, both values change, and the id cannot tell which field the user edited. So the key comes from the field itself (its name, as the cell tag field already uses it). The id only pairs each recorded key with RJSF's onChange call. A field can pass on several changes before RJSF calls onChange (the reviewer's custom field reports an intermediate and a final value in one click), so the keys wait in a queue per id.

Jest results for metadataFormWidget.spec.ts with the tests of the patch (40 tests, including a collision, array add/remove/move and two-changes cases):

version failing
main 12
PR head 9631fba 3: switching the condition when the new branch has its own key; a custom field sending a value equal to the filled-in default; the /a / /a_b case above, where the comparison writes the default of the branch that the click selects
this patch 0

Combined with #20002 (f0dd6b4) and the test changes below, all 45 tests pass. In the browser (dev build), opening the Property Inspector and visiting cells writes nothing; edits in Common Tools and in two conditional forms from the user settings are saved; and a typed value is kept after leaving the cell and coming back.

A minor exception, the same on main and in 9631fba: RJSF sets a missing null-typed field to null itself, through the field. So a null field nested in an object saves e.g. obj: {heading: null} when the form opens. This is a pre-existing initialization write outside this change's scope and could be tracked in a follow-up.

UI tests, needed with either version: the UI tests in galata/test/jupyterlab/metadataform.test.ts still expect the old behaviour, and the PR doesn't change them yet. In "Default metadata without/with "showModified" flag", three assertions check that a default is written right after the form opens. They will fail with this PR, whichever version is used, and need to expect undefined there. One more step ("Fill the first one with default should be written in metadata") expects a default that the user enters to be saved: the fill comparison does not save it, the field-key version does. I found this by reading the tests and haven't run them.

Interaction with #20002: whichever PR is merged second should keep #20002's guarded closure for both onChange and formContext.updateMetadata. A direct onChange call no longer writes anything (no field recorded a key), and the initialization is no longer written, so #20002's tests need three changes:

  • the callback test types into the field instead of calling onChange;
  • the unmount test observes the initialization in the onChange callback and checks that nothing of it is written;
  • a new test from the reviewer checks an obsolete form for the same cell, through its field and its custom-field context, with the current form as a positive control. The unmount test no longer reaches the current-form guard, so this keeps it covered.

Removing the guard fails the callback test, writing the initialization fails the unmount test, and removing only owner.form !== this fails the new test. The diff is attached as pr20002-test-adaptation-for-field-keys-2.diff.txt. Use it when combining #20002 with the field-key patch: it relies on the typeInto helper introduced by that patch.

About #19995: I ran #20002's unmount scenario without its guard. With 9631fba, the stale form still overwrites the other cell (editable, deletable, slide_type). With this patch, it writes nothing, because the initialization is never written. #20002 is still needed for edits in a stale form and for custom fields.

Related: #17164 also ran into the Common Tools defaults while trying to remove metadata. The classic notebook stopped storing default editable/deletable values in jupyter/notebook#1865, because it "fills notebooks with redundant flags" and such values "should only be stored if defined and not-default".

Patch: pr20160-field-keys-2.patch.txt, one commit for PR revision 9631fba.
pr20160-field-keys-2.patch.txt
pr20002-test-adaptation-for-field-keys-2.diff.txt

I prepared this with Claude and Codex.

dturaev and others added 3 commits October 21, 2026 22:24
RJSF calls onChange both when the user changes a field and when it fills
in values itself, e.g. the defaults when the form is created, so writing
the whole form data writes these defaults too. Track the metadata key of
each change explicitly instead: the field of each metadata key, i.e. each
property of the root field, records its key for each change that it
passes on, and the form writes only that key. The values that the form
fills in for other keys come without such a record. A changed key is
written with its whole value, e.g. an object with the defaults filled in
it. This replaces skipping the values of missing metadata that equal a
default, which also skips such a value when the user enters it.

The field id alone does not identify the key: it joins the names of the
key and of the nested fields with `_`, which keys may contain too. It
only pairs each recorded key with the report of its change. A field may
pass on several changes before the form reports them, so the keys wait
in a queue per id.

A null field sets a missing value to null from an effect, which is
recorded like a change. The cell model ignores null for a missing key,
but a null field nested in an object still writes the object, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UVgHJTXiavHWWyVC9dv2vF
RJSF calls onChange with the id of the changed field as a second
argument, and the metadata form relies on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@b84330808

Copy link
Copy Markdown
Contributor Author

Thanks @dturaev, this is much nicer than the fill comparison. Tracking the key per field avoids guessing, and it also saves a default that the user types on purpose, which the galata test expects anyway.

I applied the patch locally and got the same numbers: 12 failing on main, 3 on 9631fba, 0 with your patch. I've pushed it to this PR with your commit as is, plus two small commits on top:

  • id?: string on IFormComponentProps.onChange, so the dependency on RJSF's id is explicit
  • the three galata assertions that expected a default right after the form opens now expect undefined. I haven't run galata locally, so CI will be the first run.

On #20002: if this one is merged second, I'll keep its guarded closure for both onChange and formContext.updateMetadata.

@dturaev

dturaev commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Thanks for taking it! One remaining documentation test appears to need updating: “Right Sidebar” in galata/test/documentation/general.test.ts.
It still expects "tags": [] after opening Common Tools on a new raw cell. It also clicks the eighth line of the metadata editor, which contains the tags only when the previous default metadata is present.
The attached patch checks that opening Common Tools leaves tags absent, then locates the existing test-tag line by content within the cell metadata editor. It preserves the subsequent check that manually editing the JSON updates the tags.
I haven’t run the UI tests locally. The interface-right-advanced-documentation-linux.png reference screenshot also contains the old defaults and will need regeneration after this patch is applied and CI reruns.
pr20160-docs-test.patch.txt

Opening Common Tools no longer writes the default metadata into the new
raw cell, so its metadata has no tags, and the line of the added tag is
no longer the eighth line of the metadata editor. Click that line by its
content instead. The screenshot of the advanced tools changes as well.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UVgHJTXiavHWWyVC9dv2vF
@b84330808

Copy link
Copy Markdown
Contributor Author

Thanks for catching that! I've added your commit on top. I can't run galata locally either, so let's see what CI says, and then the advanced tools screenshot can be regenerated.

@b84330808

Copy link
Copy Markdown
Contributor Author

The only failure left is interface_right_advanced.png, which changes as expected since defaults aren't written anymore. Could someone trigger the snapshot update?

@krassowski

Copy link
Copy Markdown
Member

bot please open PR to update snapshots

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Conditional metadata loading can throw, and persistence now depends on callback ordering that still needs runtime validation.

1 open issue
What changed in this PR

This PR prevents the Property Inspector from adding default cell metadata merely when opened or when an unrelated field changes, addressing #17562.

Changes:

  • Track field changes and write only the corresponding metadata key.
  • Load existing conditional metadata values and extract lazy validator loading.
  • Add regression coverage and update browser tests to expect absent defaults.
File Description
yarn.lock Record the metadataform utilities dependency.
packages/​ui-components/​src/​components/​form.tsx Declare the optional change-event field ID.
packages/​metadataform/​test/​metadataFormWidget.spec.ts Cover defaults, conditional fields, and targeted writes.
packages/​metadataform/​src/​validator.ts Extract lazy validator loading.
packages/​metadataform/​src/​metadataform.ts Load existing values for conditional keys.
packages/​metadataform/​src/​form.tsx Track changed keys and restrict metadata writes.
packages/​metadataform/​package.json Add the RJSF utilities dependency.
galata/​test/​jupyterlab/​metadataform.test.ts Expect defaults to remain unwritten on opening.
galata/​test/​documentation/​general.test.ts Update metadata expectations and editor targeting.

Review effort: Balanced

)) {
// Include the keys of the conditional branches, so that the form shows
// their current values instead of their defaults.
for (let metadataKey of this.metadataKeys) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fix for this, with tests, is attached to this comment. @b84330808, would you like to include it here, or should I open a separate issue and PR for it once this one is merged?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MUFFANUJ's example convinced me: this PR is what makes the form evaluate those inactive branches, so it belongs here. Applied your patch in 74c6522 (with you as the author). Thanks!

@galata-snapshots-bot

Copy link
Copy Markdown
Contributor

@dturaev

dturaev commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Copilot’s point is valid. The underlying traversal bug predates this PR: ordinary keys such as /slideshow/slide_type already fail when their parent is null or a primitive. Loading conditional keys exposes additional cases, including the valid conditional metadata in Copilot’s example.

Writing and removing nested keys have related weaknesses. Removal can even delete a stored primitive because the empty-object cleanup treats it as an empty object.

The attached patch treats a non-object parent as a missing path when loading, replaces it with an object when writing a nested value, and preserves it when removing a nonexistent nested value. Eleven tests cover these cases; ten fail without the change, and the eleventh is a control checking that empty objects are still pruned. The focused suite, including #20002’s regressions, passes all 56 tests.

Regarding callback ordering: rendered React tests under Jest/jsdom exercise two changes reported in one interaction, colliding field IDs, and a oneOf option. The PR’s UI tests exercise ordinary form editing, and additional browser checks covered Common Tools and conditional forms. Those browser checks do not specifically cover every ordering edge case.

@b84330808, could you add the patch to this PR if it looks good to you?

Prepared with help from Claude and Codex.
pr20160-non-object-parents.patch.txt

The snapshot bot changed it, but this PR doesn't touch the context menu.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread packages/metadataform/src/validator.ts Resolved
They moved to validator.ts so that metadataform.ts could use the
validator as well. Since the form writes only the metadata key of the
changed field, metadataform.ts no longer uses it, so keep the helpers
in form.tsx as on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UVgHJTXiavHWWyVC9dv2vF
krassowski pushed a commit that referenced this pull request Oct 28, 2026
#20305)

## References

Fixes #20304
 
The doubled entry also showed up in a documentation snapshot in #20160.
The entries were added in 4.5.0 (#17848), so 4.6.x is affected as well.

## Code changes

The `create-new-language-file` plugin rebuilds its entries at startup
and on `specsChanged`. When the kernel specs arrive after the plugin has
activated, a second rebuild starts while the first one is still awaiting
`getAvailableKernelFileTypes`. Each rebuild disposed of the previous
entries before that await, so both kept their entries. The rebuild now
disposes of the previous entries after the await, as the file editor's
`updateKernelFileTypeComponents` does, so the last rebuild replaces the
entries of the earlier ones.
 
The test is a short Galata test, because the extension package has no
Jest setup. It holds back the kernel specs response until the plugin has
activated, which makes the race happen on every run. It is in its own
commit before the fix.

## User-facing changes

"New Python File", and likewise "New R File" and "New Julia File", no
longer appear twice in the file browser context menu when the kernel
specs load slowly.
 
Kernel specs response held back by 3 seconds:
 
| Before | After |
| --- | --- |
| <img width="426" height="226" alt="language-entries-before"
src="https://github.com/user-attachments/assets/f1c9b46b-3499-433f-9ebb-d9075db8680f"
/> | <img width="426" height="202" alt="language-entries-after"
src="https://github.com/user-attachments/assets/1223fa87-9dc1-483f-bf5a-fbad63f75230"
/> |

## Backwards-incompatible changes

None.

## AI usage

- **YES**: Some or all of the content of this PR was generated by AI.
- **Yes**: The human author has carefully reviewed this PR and run this
code
- AI tools and models used: Claude (Opus 5.5, max effort)
@MUFFANUJ

Copy link
Copy Markdown
Member

I’m not sure how often users will encounter this, but a custom conditional form can hit it when an inactive branch defines /options/enabled while the cell has options: false. Loading all metadataKeys then evaluates 'enabled' in false and throws, preventing the form from opening.

Maybe we should check that intermediate values are non-null objects before using in, treating other values as missing paths.

@dturaev

dturaev commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

@MUFFANUJ Thanks, that’s the case Copilot flagged too. The patch attached to this comment does what you suggest: it treats a non-object parent as a missing path when loading. Your example confirms it: on main the form opens, on this PR it throws Cannot use 'in' operator to search for 'enabled' in false, and with the patch it opens again. Since loading the keys of inactive branches is new in this PR (it came with my first patch), I think the fix belongs here rather than in a follow-up.

@MUFFANUJ

Copy link
Copy Markdown
Member

that’s the case Copilot flagged too

Thanks, I missed that. Verified the patch locally, and it looks fine to include in this PR.

dturaev and others added 4 commits October 29, 2026 09:55
The metadata form navigated the path of a nested key, such as
`/slideshow/slide_type`, with `in` and `Object.keys`. These throw for
null and strings, and treat other values that are not objects, such as
numbers, as empty objects that are pruned. Treat such a value as missing
when the form loads the metadata, replace it by an object when the form
writes a value to the nested key, and keep it when the form removes the
nested key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UVgHJTXiavHWWyVC9dv2vF

@krassowski krassowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@krassowski
krassowski merged commit 50a3fca into jupyterlab:main Oct 30, 2026
122 checks passed
Mrun25 added a commit to Mrun25/jupyterlab that referenced this pull request Oct 30, 2026
Mrun25 pushed a commit to Mrun25/jupyterlab that referenced this pull request Oct 30, 2026
When merging main, take form.tsx from main, where the form writes only
the metadata key of the changed field (jupyterlab#20160), and route those writes
and the custom-field updates through the guarded updateMetadata again.

Since jupyterlab#20160, the form no longer writes during its initialization. The
tests now observe the stale initialization where RJSF reports it and
change fields through the form; a test for an obsolete form of the same
cell is added. Also fix the lint errors in the tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UVgHJTXiavHWWyVC9dv2vF
krassowski added a commit that referenced this pull request Nov 6, 2026
## References

Fixes #19995.

## Code changes

FormWidget captures the cell it was built for. Updates are skipped when
that cell is no longer active, or when the form has been replaced or its
owner disposed. Both field edits and custom-field updates use the same
guard.

This version incorporates main after #20160. It preserves that change's
field-key-only writes and avoidance of initialization/default writes.
Regression tests cover a form built for a different cell, an obsolete
form for the same cell, and a collapsed form that mounts again after the
active cell changed, as it does when another notebook gets the focus.

The follow-up adapts and includes dturaev's supplied patch and
regression test, prepared with AI assistance.

> **Added by a maintainer**
>
> - Rebuilds the form when the notebook tools are attached while
visible, and drops it when they are attached while hidden, so that a
stale form is not mounted again.
> - Holds the model of the source cell through a `WeakRef`, so that a
form that is not rebuilt does not keep a closed notebook in memory.

## User-facing changes

Edits in a stale metadata form cannot overwrite another cell's metadata
or newer metadata from its replacement form.

> **Added by a maintainer**
>
> The Property Inspector shows the tags of the active cell after another
document had the focus, so a click on a tag no longer copies the tags of
the previous notebook's cell.

| Before | After |
| --- | --- |
| <img width="250" height="170" alt="pr20002-e89df782e1-before"
src="https://github.com/user-attachments/assets/8b936f21-abae-4a8e-89f0-9a0f7bda532a"
/> | <img width="250" height="170" alt="pr20002-e89df782e1-after"
src="https://github.com/user-attachments/assets/639b6b50-8302-470c-b526-ec453c2083f9"
/>


## Backwards-incompatible changes

None.

## AI usage

- **YES**: Some or all of the content of this PR was generated by AI.
- **NOT CONFIRMED**: The human author has carefully reviewed this PR and
run this code. This requirement has not yet been confirmed; the PR
remains a draft pending confirmation.
- AI assistance was used for implementation and testing. Automated test
runs are not a substitute for the required human review and execution.
Claude Code (Opus 5.5, max effort) was used for the maintainer changes.

---------

Co-authored-by: dturaev <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: krassowski <[email protected]>
krassowski added a commit that referenced this pull request Nov 6, 2026
… built for another cell) (#20417)

Backport PR #20002 on
branch 4.6.x (Do not write metadata from a form built for another cell)

#20160 is not on 4.6.x, so the guarded `onChange` still writes the whole
form data, and the spec adds the `typeInto` helper that main got from
#20160.

Co-authored-by: Mrunmayee Daware <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

default cell metadata gets inserted by the property inspector

6 participants