Skip to content

Conversation

@miya
Copy link
Member

@miya miya commented Nov 28, 2025

@miya miya requested a review from yuki-takei November 28, 2025 02:30
@miya miya self-assigned this Nov 28, 2025

if (!isOpened) {
return <></>;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

dynamic import 後の HandsontableModalSubstance の不要な rerender 対策

Copy link
Contributor

Choose a reason for hiding this comment

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

今のままだとモーダルの fade エフェクトがなくなったりするという微妙なデメリットがある

ちゃんとやるなら他のモーダル (ShortcutsModal など) を参考に、一番外側の <Modal> は Container component (lightweight, always rendered) に含むように改修することになる

HandsontableModalSubstance は view / editor の場合分けなしに両対応するとして、
それをラップする HandsontableModal 側で場合分けすべきかなと思う

ちなみに DrawioModal も同じかもしれない

Copy link
Member Author

Choose a reason for hiding this comment

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

ShortcutsModal を参考に修正しました。
View / Editor の場合分けは HandsontableModal で行い HandsontableModalSubstance では意識しなくて良いようにしました


export const HandsontableModalSubstance = (): JSX.Element => {

const HandsontableModalSubstance = (): JSX.Element => {
Copy link
Member Author

Choose a reason for hiding this comment

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

不要な export の削除


// Memoize modal open handler
const handleModalOpen = useCallback(() => {
const markdownTableState = table == null && editor != null ? getMarkdownTable(editor) : table;
Copy link
Member Author

Choose a reason for hiding this comment

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

バグの原因

エディターからモーダルを開く際に、関係のない "table" という変数を見ていたから。"table" は2回目にモーダルを開く時に必ず not null になる。

変数 table について

"table" は useHandsontableModalStatus 由来のもの

const handsontableModalData = useHandsontableModalStatus();
const isOpened = handsontableModalData.isOpened;
const table = handsontableModalData?.table;

modal を閉じる際に呼ばれる close メソッドで closeHandsontableModal() が呼ばれる

const cancel = () => {
closeHandsontableModal();
closeHandsontableModalForEditor();
setIsDataImportAreaExpanded(false);
setIsWindowExpanded(false);
};

closeHandsontableModal() によって useHandsontableModalStatus の table が defaultMarkdownTable になる

const defaultMarkdownTable = () => {
return new MarkdownTable(
[
['col1', 'col2', 'col3'],
['', '', ''],
['', '', ''],
],
{
align: ['', '', ''],
},
);
};
// Atom definition
const handsontableModalAtom = atom<HandsontableModalState>({
isOpened: false,
});
// Read-only hook
export const useHandsontableModalStatus = () => {
const [state] = useAtom(handsontableModalAtom);
return state;
};
// Actions-only hook
export const useHandsontableModalActions = () => {
const setState = useSetAtom(handsontableModalAtom);
const open = (
table: MarkdownTable,
autoFormatMarkdownTable?: boolean,
onSave?: HandsontableModalSaveHandler,
) => {
setState({
isOpened: true,
table,
autoFormatMarkdownTable,
onSave,
});
};
const close = () => {
setState({
isOpened: false,
table: defaultMarkdownTable(),
autoFormatMarkdownTable: false,
onSave: undefined,
});
};
return { open, close };
};

const { close: closeHandsontableModalForEditor } = useHandsontableModalForEditorActions();
const handsontableModalForEditorData = useHandsontableModalForEditorStatus();
const isOpendInEditor = handsontableModalForEditorData.isOpened;
const editor = handsontableModalForEditorData?.editor;
Copy link
Member Author

Choose a reason for hiding this comment

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

  • どの hook 由来の変数か追いにくかったため view で使うものと editor で使うものを分けた
  • .isOpened については jotai 化したタイミング nullable ではなくなったためオプショナルチェーンを外した

}
else {
markdownTableState = table;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

View で開く場合と Editor で開く場合で処理を分けた

Copy link
Contributor

Choose a reason for hiding this comment

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

isOpenedInEditor じゃないかな (e が足りない)

Copy link
Member Author

Choose a reason for hiding this comment

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

修正しました


if (!isOpened) {
return <></>;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

今のままだとモーダルの fade エフェクトがなくなったりするという微妙なデメリットがある

ちゃんとやるなら他のモーダル (ShortcutsModal など) を参考に、一番外側の <Modal> は Container component (lightweight, always rendered) に含むように改修することになる

HandsontableModalSubstance は view / editor の場合分けなしに両対応するとして、
それをラップする HandsontableModal 側で場合分けすべきかなと思う

ちなみに DrawioModal も同じかもしれない

}
else {
markdownTableState = table;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

isOpenedInEditor じゃないかな (e が足りない)

onClick={onClickTableButton}
>
<span className="material-symbols-outlined fs-5">table_chart</span>
<span className="material-symbols-outlined fs-5">table</span>
Copy link
Member Author

Choose a reason for hiding this comment

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

HandsontableModal を呼び出すボタンのアイコンを変更しました

Before

Image

After

Image

}
else {
markdownTableState = table;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

修正しました


if (!isOpened) {
return <></>;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

ShortcutsModal を参考に修正しました。
View / Editor の場合分けは HandsontableModal で行い HandsontableModalSubstance では意識しなくて良いようにしました

@yuki-takei yuki-takei merged commit 6035e94 into dev/7.4.x Dec 3, 2025
16 checks passed
@yuki-takei yuki-takei deleted the fix/174842-cannot-update-existing-table-data-with-handson-table-modal branch December 3, 2025 09:47
@github-actions github-actions bot mentioned this pull request Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants